From c2a52782dd87e12380ecc9224925c9a68662fcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 13 Jan 2020 17:00:37 +0100 Subject: [PATCH] Memoryview, deque, threading, introspection --- README.md | 9 +++++---- index.html | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 747f115..ff5f320 100644 --- a/README.md +++ b/README.md @@ -1988,7 +1988,7 @@ Memory View = bytes() # Creates a new bytes object. = .join() # Joins mviews using bytes object as sep. = list() # Returns list of ints or floats. - = str(, 'utf-8') # Treats mview as a seqence of bytes. + = str(, 'utf-8') # Treats mview as a bytes object. = int.from_bytes(, byteorder='big/little', signed=False) '' = .hex() ``` @@ -2005,8 +2005,8 @@ from collections import deque ```python .appendleft() # Opposite element is dropped if full. - = .popleft() # Raises IndexError if empty. .extendleft() # Collection gets reversed. + = .popleft() # Raises IndexError if empty. .rotate(n=1) # Rotates elements to the right. ``` @@ -2014,7 +2014,7 @@ from collections import deque Threading --------- * **CPython interpreter can only run a single thread at a time.** -* **That is why using multiple threads won't result in a faster execution, unless there is an I/O operation in the thread.** +* **That is why using multiple threads won't result in a faster execution, unless one of the threads contains an I/O operation.** ```python from threading import Thread, RLock ``` @@ -2071,7 +2071,7 @@ from queue import Queue .put() # Blocks until queue stops being full. .put_nowait() # Raises queue.Full exception if full. = .get() # Blocks until queue stops being empty. - = .get_nowait() # Raises _queue.Empty exception if empty. + = .get_nowait() # Raises queue.Empty exception if empty. ``` @@ -2125,6 +2125,7 @@ from inspect import signature = signature() no_of_params = len(.parameters) param_names = list(.parameters.keys()) +param_kinds = [a.kind for a in .parameters.values()] ``` diff --git a/index.html b/index.html index c78929e..5abf03f 100644 --- a/index.html +++ b/index.html @@ -1761,7 +1761,7 @@ db = connector.connect(host=<str>, user=<str>, password=<str>, <bytes> = bytes(<mview>) # Creates a new bytes object. <bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes object as sep. <list> = list(<mview>) # Returns list of ints or floats. -<str> = str(<mview>, 'utf-8') # Treats mview as a seqence of bytes. +<str> = str(<mview>, 'utf-8') # Treats mview as a bytes object. <int> = int.from_bytes(<mview>, byteorder='big/little', signed=False) '<hex>' = <mview>.hex() @@ -1772,13 +1772,13 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,
<deque>.appendleft(<el>)                       # Opposite element is dropped if full.
-<el> = <deque>.popleft()                       # Raises IndexError if empty.
 <deque>.extendleft(<collection>)               # Collection gets reversed.
+<el> = <deque>.popleft()                       # Raises IndexError if empty.
 <deque>.rotate(n=1)                            # Rotates elements to the right.
 

#Threading

  • CPython interpreter can only run a single thread at a time.
  • -
  • That is why using multiple threads won't result in a faster execution, unless there is an I/O operation in the thread.
  • +
  • That is why using multiple threads won't result in a faster execution, unless one of the threads contains an I/O operation.
from threading import Thread, RLock
 
@@ -1824,7 +1824,7 @@ lock.release()
<Queue>.put(<el>)                    # Blocks until queue stops being full.
 <Queue>.put_nowait(<el>)             # Raises queue.Full exception if full.
 <el> = <Queue>.get()                 # Blocks until queue stops being empty.
-<el> = <Queue>.get_nowait()          # Raises _queue.Empty exception if empty.
+<el> = <Queue>.get_nowait()          # Raises queue.Empty exception if empty.
 

#Operator

Module of functions that provide the functionality of operators.

from operator import add, sub, mul, truediv, floordiv, mod, pow, neg, abs
 from operator import eq, ne, lt, le, gt, ge
@@ -1860,6 +1860,7 @@ delattr(<object>, '<attr_name>')
 <sig>        = signature(<function>)
 no_of_params = len(<sig>.parameters)
 param_names  = list(<sig>.parameters.keys())
+param_kinds  = [a.kind for a in <sig>.parameters.values()]
 

#Metaprograming

Code that generates code.

Type

Type is the root class. If only passed an object it returns its type (class). Otherwise it creates a new class.

<class> = type('<class_name>', <parents_tuple>, <attributes_dict>)