From 963925032b82f32b4f28dee46be121d43d74d511 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 27 Sep 2024 19:58:21 +0200 Subject: [PATCH] Memoryview --- README.md | 16 ++++++++-------- index.html | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 5c8518f..3fa3208 100644 --- a/README.md +++ b/README.md @@ -2044,7 +2044,7 @@ from array import array = array('', ) # Array from collection of numbers. = array('', ) # Copies bytes to array's memory. = array('', ) # Treats array as a sequence of numbers. -.fromfile(, n_items) # Appends items from binary file. +.fromfile(, n_items) # Appends items from the binary file. ``` ```python @@ -2058,23 +2058,23 @@ 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.** ```python - = memoryview() # Immutable if bytes, else mutable. - = [index] # Returns int/float (bytes if format is 'c'). - = [] # Returns mview with rearranged elements. + = memoryview() # Immutable if bytes is passed, else mutable. + = [index] # Returns int/float. Bytes if format is 'c'. + = [] # Returns memoryview 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 as a separator. - = array('', ) # Treats mview as a sequence of numbers. -.write() # Writes `bytes()` to binary file. + = .join() # Joins memoryviews using bytes as a separator. + = array('', ) # Treats memoryview as a sequence of numbers. +.write() # Writes `bytes()` to the binary file. ``` ```python = list() # Returns a list of ints, floats or bytes. - = str(, 'utf-8') # Treats mview as a bytes object. + = str(, 'utf-8') # Treats memoryview as a bytes object. = .hex() # Returns hex pairs. Accepts `sep=`. ``` diff --git a/index.html b/index.html index e3d1869..2d4c440 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1692,26 +1692,26 @@ CompletedProcess(args=['bc', <array> = array('<typecode>', <coll_of_nums>) # Array from collection of numbers. <array> = array('<typecode>', <bytes>) # Copies bytes to array's memory. <array> = array('<typecode>', <array>) # Treats array as a sequence of numbers. -<array>.fromfile(<file>, n_items) # Appends items from binary file. +<array>.fromfile(<file>, n_items) # Appends items from the binary file.
<bytes> = bytes(<array>)                       # Returns a copy of array's memory.
 <file>.write(<array>)                          # Writes array's memory to 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.

<mview> = memoryview(<bytes/bytearray/array>)  # Immutable if bytes, else mutable.
-<obj>   = <mview>[index]                       # Returns int/float (bytes if format is 'c').
-<mview> = <mview>[<slice>]                     # Returns mview with rearranged elements.
+

#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 is passed, else mutable.
+<obj>   = <mview>[index]                       # Returns int/float. Bytes if format is 'c'.
+<mview> = <mview>[<slice>]                     # Returns memoryview 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 as a separator.
-<array> = array('<typecode>', <mview>)         # Treats mview as a sequence of numbers.
-<file>.write(<mview>)                          # Writes `bytes(<mview>)` to binary file.
+<bytes> = <bytes>.join(<coll_of_mviews>)       # Joins memoryviews using bytes as a separator.
+<array> = array('<typecode>', <mview>)         # Treats memoryview as a sequence of numbers.
+<file>.write(<mview>)                          # Writes `bytes(<mview>)` to the binary file.
 
<list>  = list(<mview>)                        # Returns a list of ints, floats or bytes.
-<str>   = str(<mview>, 'utf-8')                # Treats mview as a bytes object.
+<str>   = str(<mview>, 'utf-8')                # Treats memoryview as a bytes object.
 <str>   = <mview>.hex()                        # 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
@@ -2931,7 +2931,7 @@ $ deactivate                # Deactivates the active