diff --git a/README.md b/README.md index 4dbb9ee..92254ab 100644 --- a/README.md +++ b/README.md @@ -1546,7 +1546,7 @@ value = args. * **Use `'help='` to set argument description that will be displayed in help message.** * **Use `'default='` to set the default value.** -* **Use `'type=FileType()'` for files. Also accepts 'encoding', but not 'newline'.** +* **Use `'type=FileType()'` for files. Accepts 'encoding', but 'newline' is always None.** Open @@ -1672,7 +1672,7 @@ from pathlib import Path ```python = Path() # Returns relative cwd. Also Path('.'). = Path.cwd() # Returns absolute cwd. Also Path().resolve(). - = Path.home() # Returns user's home directory. + = Path.home() # Returns user's home directory (absolute). = Path(__file__).resolve() # Returns script's path if cwd wasn't changed. ``` @@ -1828,13 +1828,13 @@ import csv * **File must be opened with a `'newline=""'` argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!** ### Parameters -* **`'dialect'` - Master parameter that sets the default values. String or a dialect object.** +* **`'dialect'` - Master parameter that sets the default values. String or a Dialect object.** * **`'delimiter'` - A one-character string used to separate fields.** * **`'quotechar'` - Character for quoting fields that contain special characters.** * **`'doublequote'` - Whether quotechars inside fields are/get doubled or escaped.** * **`'skipinitialspace'` - Whether whitespace after delimiter gets stripped by reader.** * **`'lineterminator'` - How writer terminates rows. Reader is hardcoded to '\n', '\r', '\r\n'.** -* **`'quoting'` - Controls the amount of quoting: 0 - as necessary, 1 - all.** +* **`'quoting'` - 0: As necessary, 1: All, 2: All but numbers which are read as floats, 3: None.** * **`'escapechar'` - Character for escaping quotechars if doublequote is False.** ### Dialects @@ -1982,16 +1982,11 @@ Struct * **System’s type sizes, byte order, and alignment rules are used by default.** ```python -from struct import pack, unpack, iter_unpack +from struct import pack, unpack + = pack('', [, ...]) # Packages arguments into bytes object. + = unpack('', ) # Use iter_unpack() for iterator of tuples. ``` -```python - = pack('', [, , ...]) - = unpack('', ) - = iter_unpack('', ) -``` - -### Example ```python >>> pack('>hhl', 1, 2, 3) b'\x00\x01\x00\x02\x00\x00\x00\x03' @@ -2001,12 +1996,15 @@ b'\x00\x01\x00\x02\x00\x00\x00\x03' ### Format #### For standard type sizes and manual alignment (padding) start format string with: -* **`'='` - system's byte order (usually little-endian)** -* **`'<'` - little-endian** -* **`'>'` - big-endian (also `'!'`)** +* **`'='` - System's byte order (usually little-endian).** +* **`'<'` - Little-endian.** +* **`'>'` - Big-endian (also `'!'`).** + +#### Besides numbers, pack() and unpack() also support bytes objects as part of the seqence: +* **`'c'` - A bytes object with single element. Use `'x'` for pad byte.** +* **`'s'` - A bytes object with n elements.** #### Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets: -* **`'x'` - pad byte** * **`'b'` - char (1/1)** * **`'h'` - short (2/2)** * **`'i'` - int (2/4)** @@ -2037,7 +2035,8 @@ Memory View * **A sequence object that points to the memory of another object.** * **Each element can reference a single or multiple consecutive bytes, depending on format.** * **Order and number of elements can be changed with slicing.** -* **Casting only works between char and other types and uses system's sizes and byte order.** +* **Casting only works between char and other types and uses system's sizes.** +* **Byte order is always determined by the system.** ```python = memoryview() # Immutable if bytes, else mutable. diff --git a/index.html b/index.html index b6bef04..2007bd3 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1322,7 +1322,7 @@ value = args.<name>
  • Use 'help=<str>' to set argument description that will be displayed in help message.
  • Use 'default=<el>' to set the default value.
  • -
  • Use 'type=FileType(<mode>)' for files. Also accepts 'encoding', but not 'newline'.
  • +
  • Use 'type=FileType(<mode>)' for files. Accepts 'encoding', but 'newline' is always None.

#Open

Opens the file and returns a corresponding file object.

<file> = open(<path>, mode='r', encoding=None, newline=None)
 
@@ -1417,7 +1417,7 @@ value = args.<name>
<Path> = Path()                     # Returns relative cwd. Also Path('.').
 <Path> = Path.cwd()                 # Returns absolute cwd. Also Path().resolve().
-<Path> = Path.home()                # Returns user's home directory.
+<Path> = Path.home()                # Returns user's home directory (absolute).
 <Path> = Path(__file__).resolve()   # Returns script's path if cwd wasn't changed.
 
<Path> = <Path>.parent              # Returns Path without the final component.
@@ -1526,13 +1526,13 @@ CompletedProcess(args=['bc', 'newline=""' argument, or '\r' will be added in front of every '\n' on platforms that use '\r\n' line endings!
 
 

Parameters

    -
  • 'dialect' - Master parameter that sets the default values. String or a dialect object.
  • +
  • 'dialect' - Master parameter that sets the default values. String or a Dialect object.
  • 'delimiter' - A one-character string used to separate fields.
  • 'quotechar' - Character for quoting fields that contain special characters.
  • 'doublequote' - Whether quotechars inside fields are/get doubled or escaped.
  • 'skipinitialspace' - Whether whitespace after delimiter gets stripped by reader.
  • 'lineterminator' - How writer terminates rows. Reader is hardcoded to '\n', '\r', '\r\n'.
  • -
  • 'quoting' - Controls the amount of quoting: 0 - as necessary, 1 - all.
  • +
  • 'quoting' - 0: As necessary, 1: All, 2: All but numbers which are read as floats, 3: None.
  • 'escapechar' - Character for escaping quotechars if doublequote is False.

Dialects

┏━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓
 ┃                  │     excel    │   excel-tab  │     unix     ┃
@@ -1643,26 +1643,25 @@ CompletedProcess(args=['bc', #Struct
  • Module that performs conversions between a sequence of numbers and a bytes object.
  • System’s type sizes, byte order, and alignment rules are used by default.
  • -
from struct import pack, unpack, iter_unpack
+
from struct import pack, unpack
+<bytes> = pack('<format>', <el> [, ...])  # Packages arguments into bytes object.
+<tuple> = unpack('<format>', <bytes>)     # Use iter_unpack() for iterator of tuples.
 
-
<bytes>  = pack('<format>', <num_1> [, <num_2>, ...])
-<tuple>  = unpack('<format>', <bytes>)
-<tuples> = iter_unpack('<format>', <bytes>)
-
-

Example

>>> pack('>hhl', 1, 2, 3)
+
>>> pack('>hhl', 1, 2, 3)
 b'\x00\x01\x00\x02\x00\x00\x00\x03'
 >>> unpack('>hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03')
 (1, 2, 3)
-
- -

Format

For standard type sizes and manual alignment (padding) start format string with:

    -
  • '=' - system's byte order (usually little-endian)
  • -
  • '<' - little-endian
  • -
  • '>' - big-endian (also '!')
  • -

Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:

    -
  • 'x' - pad byte
  • +
+

Format

For standard type sizes and manual alignment (padding) start format string with:

    +
  • '=' - System's byte order (usually little-endian).
  • +
  • '<' - Little-endian.
  • +
  • '>' - Big-endian (also '!').
  • +

Besides numbers, pack() and unpack() also support bytes objects as part of the seqence:

    +
  • 'c' - A bytes object with single element. Use 'x' for pad byte.
  • +
  • '<n>s' - A bytes object with n elements.
  • +

Integer types. Use a capital letter for unsigned type. Minimum and standard sizes are in brackets:

  • 'b' - char (1/1)
  • 'h' - short (2/2)
  • 'i' - int (2/4)
  • @@ -1671,7 +1670,9 @@ CompletedProcess(args=['bc', Floating point types:
    • 'f' - float (4/4)
    • 'd' - double (8/8)
    • -
+
+ + @@ -1691,7 +1692,8 @@ CompletedProcess(args=['bc', <mview> = memoryview(<bytes/bytearray/array>) # Immutable if bytes, else mutable. <real> = <mview>[<index>] # Returns an int or a float. <mview> = <mview>[<slice>] # Mview with rearranged elements. @@ -2195,7 +2197,7 @@ right = [[0.1 , 0.6< right = [[0.1, 0.6, 0.8], [0.1, 0.6, 0.8], [0.1, 0.6, 0.8]] # Shape: (3, 3) <- !
-

3. If neither non-matching dimension has size 1, raise an error.

Example

For each point returns index of its nearest point ([0.1, 0.6, 0.8] => [1, 2, 1]):

>>> points = np.array([0.1, 0.6, 0.8])
+

3. If neither non-matching dimension has size 1, raise an error.

Example

For each point returns index of its nearest point ([0.1, 0.6, 0.8] => [1, 2, 1]):

>>> points = np.array([0.1, 0.6, 0.8])
  [ 0.1,  0.6,  0.8]
 >>> wrapped_points = points.reshape(3, 1)
 [[ 0.1],
@@ -2901,7 +2903,7 @@ $ pyinstaller script.py --add-data '<path>:.'  
  
 
   
 
diff --git a/parse.js b/parse.js
index e84051f..d4ecd75 100755
--- a/parse.js
+++ b/parse.js
@@ -76,6 +76,9 @@ const OS_RENAME =
   'os.rename(from, to)              # Renames/moves the file or directory.\n' +
   'os.replace(from, to)             # Same, but overwrites \'to\' if it exists.\n';
 
+const STRUCT_FORMAT =
+  '\'<n>s\'';
+
 const TYPE =
   '<class> = type(\'<class_name>\', <tuple_of_parents>, <dict_of_class_attributes>)';
 
@@ -478,6 +481,7 @@ function modifyPage() {
   fixPandasDiagram();
   removePlotImages();
   fixABCSequenceDiv();
+  fixStructFormatDiv();
 }
 
 function changeMenu() {
@@ -569,6 +573,7 @@ function fixHighlights() {
   $(`code:contains(make_dataclass(\'\')`).html(DATACLASS);
   $(`code:contains(shutil.copy)`).html(SHUTIL_COPY);
   $(`code:contains(os.rename)`).html(OS_RENAME);
+  $(`code:contains(\'s\')`).html(STRUCT_FORMAT);
   $(`code:contains(\'\', , )`).html(TYPE);
   $(`code:contains(ValueError: malformed node)`).html(EVAL);
   $(`code:contains(pip3 install tqdm)`).html(PROGRESS_BAR);
@@ -633,6 +638,19 @@ function fixABCSequenceDiv() {
   $('#abcsequence').parent().insertBefore($('#tableofrequiredandautomaticallyavailablespecialmethods').parent())
 }
 
+function fixStructFormatDiv() {
+  const div = $('#format-2').parent()
+  $('#format-2').insertBefore(div)
+  $('#forstandardtypesizesandmanualalignmentpaddingstartformatstringwith').parent().insertBefore(div)
+}
+
+
+function fixStructFormat() {
+  const div = $('#format-2').parent()
+  $('#format-2').insertBefore(div)
+  $('#forstandardtypesizesandmanualalignmentpaddingstartformatstringwith').parent().insertBefore(div)
+}
+
 function updateDate(template) {
   const date = new Date();
   const date_str = date.toLocaleString('en-us', {month: 'long', day: 'numeric', year: 'numeric'});