diff --git a/README.md b/README.md index ca75107..7dad4c6 100644 --- a/README.md +++ b/README.md @@ -1998,7 +1998,8 @@ Struct ```python from struct import pack, unpack - = pack('', [, ...]) # Packages arguments. Can raise struct.error. + + = pack('', [, ...]) # Packs objects according to format string. = unpack('', ) # Use iter_unpack() to get iterator of tuples. ``` @@ -2054,23 +2055,19 @@ from array import array Memory View ----------- -* **A sequence object that points to the memory of another bytes-like 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.** -* **Byte order is always determined by the system.** +**A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.** ```python = memoryview() # Immutable if bytes, else mutable. = [index] # Returns an int or a float. - = [] # Mview with rearranged elements. - = .cast('') # Casts memoryview to the new format. -.release() # Releases memory buffer of target object. + = [] # Returns mview with rearranged elements. + = .cast('') # Only works between b/B/c and other types. +.release() # Releases memory buffer of the base object. ``` ```python = bytes() # Returns a new bytes object. - = .join() # Joins mviews using bytes object as sep. + = .join() # Joins mviews using bytes as a separator. = array('', ) # Treats mview as a sequence of numbers. .write() # Writes mview to the binary file. ``` @@ -2088,11 +2085,14 @@ Deque ```python from collections import deque +``` + +```python = deque() # Also `maxlen=None`. .appendleft() # Opposite element is dropped if full. -.extendleft() # Collection gets reversed. - = .popleft() # Raises IndexError if empty. +.extendleft() # Passed collection gets reversed. .rotate(n=1) # Rotates elements to the right. + = .popleft() # Raises IndexError if empty. ``` diff --git a/index.html b/index.html index 5640f25..3dbf04f 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1648,7 +1648,8 @@ CompletedProcess(args=['bc', from struct import pack, unpack -<bytes> = pack('<format>', <el_1> [, ...]) # Packages arguments. Can raise struct.error. + +<bytes> = pack('<format>', <el_1> [, ...]) # Packs objects according to format string. <tuple> = unpack('<format>', <bytes>) # Use iter_unpack() to get iterator of tuples. @@ -1695,22 +1696,16 @@ CompletedProcess(args=['bc', <bytes> = bytes(<array>) # Converts array to a bytes object. <file>.write(<array>) # Writes array to the binary file. -

#Memory View

    -
  • A sequence object that points to the memory of another bytes-like 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.
  • -
  • Byte order is always determined by the system.
  • -
<mview> = memoryview(<bytes/bytearray/array>)  # Immutable if bytes, else mutable.
+

#Memory View

A sequence object that points to the memory of another bytes-like object. Each element can reference a single or multiple consecutive bytes, depending on format. Order and number of elements can be changed with slicing.

<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.
-<mview> = <mview>.cast('<typecode>')           # Casts memoryview to the new format.
-<mview>.release()                              # Releases memory buffer of target object.
+<mview> = <mview>[<slice>]                     # Returns mview with rearranged elements.
+<mview> = <mview>.cast('<typecode>')           # Only works between b/B/c and other types.
+<mview>.release()                              # Releases memory buffer of the base object.
 
<bytes> = bytes(<mview>)                       # Returns a new bytes object.
-<bytes> = <bytes>.join(<coll_of_mviews>)       # Joins mviews using bytes object as sep.
+<bytes> = <bytes>.join(<coll_of_mviews>)       # Joins mviews using bytes as a separator.
 <array> = array('<typecode>', <mview>)         # Treats mview as a sequence of numbers.
 <file>.write(<mview>)                          # Writes mview to the binary file.
 
@@ -1719,14 +1714,15 @@ CompletedProcess(args=['bc', # Returns hex pairs. Accepts `sep=<str>`.

#Deque

A thread-safe list with efficient appends and pops from either side. Pronounced "deck".

from collections import deque
-<deque> = deque(<collection>)                  # Also `maxlen=None`.
-<deque>.appendleft(<el>)                       # Opposite element is dropped if full.
-<deque>.extendleft(<collection>)               # Collection gets reversed.
-<el> = <deque>.popleft()                       # Raises IndexError if empty.
-<deque>.rotate(n=1)                            # Rotates elements to the right.
 
+
<deque> = deque(<collection>)                  # Also `maxlen=None`.
+<deque>.appendleft(<el>)                       # Opposite element is dropped if full.
+<deque>.extendleft(<collection>)               # Passed collection gets reversed.
+<deque>.rotate(n=1)                            # Rotates elements to the right.
+<el> = <deque>.popleft()                       # Raises IndexError if empty.
+

#Threading

CPython interpreter can only run a single thread at a time. Using multiple threads won't result in a faster execution, unless at least one of the threads contains an I/O operation.

from threading import Thread, Timer, RLock, Semaphore, Event, Barrier
 from concurrent.futures import ThreadPoolExecutor, as_completed
 
@@ -2936,7 +2932,7 @@ $ deactivate # Deactivates the activ