From 130971c943c6b674af3f55031fc9b1012d8ddb0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 28 Jul 2019 18:11:52 +0200 Subject: [PATCH] Threading and Eval repositioned --- README.md | 29 +++++++++++++++-------------- index.html | 23 +++++++++++++---------- parse.js | 2 +- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index e56b24a..fe67e9a 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Contents **   ** **3. Syntax:** **         ** **[`Args`](#arguments)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Duck_Types`](#duck-types)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__ **   ** **4. System:** **        ** **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__ **   ** **5. Data:** **             ** **[`CSV`](#csv)**__,__ **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`MemoryView`](#memory-view)**__,__ **[`Deque`](#deque)**__.__ -**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Operator`](#operator)**__,__ **[`Eval`](#eval)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Coroutine`](#coroutine)**__.__ +**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Operator`](#operator)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutine`](#coroutine)**__.__ **   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profile)**__,__ **                                 ** **[`NumPy`](#numpy)**__,__ **[`Image`](#image)**__,__ **[`Audio`](#audio)**__.__ @@ -1994,6 +1994,7 @@ with ThreadPoolExecutor(max_workers=None) as executor: results = executor.map(lambda x: x + 1, range(3)) # (1, 2, 3) results = executor.map(lambda x, y: x + y, 'abc', '123') # ('a1', 'b2', 'c3') ``` +* **CPython interpreter can only run a single thread at the time. That is why this map() won't be faster than the standard map() unless passed function contains an I/O operation.** Operator @@ -2015,19 +2016,6 @@ last_el = op.methodcaller('pop')() ``` -Eval ----- -```python ->>> from ast import literal_eval ->>> literal_eval('1 + 2') -3 ->>> literal_eval('[1, 2, 3]') -[1, 2, 3] ->>> literal_eval('abs(1)') -ValueError: malformed node or string -``` - - Introspection ------------- **Inspecting code at runtime.** @@ -2142,6 +2130,19 @@ MyMetaClass.__base__ == type # MyMetaClass is a subclass of type. ``` +Eval +---- +```python +>>> from ast import literal_eval +>>> literal_eval('1 + 2') +3 +>>> literal_eval('[1, 2, 3]') +[1, 2, 3] +>>> literal_eval('abs(1)') +ValueError: malformed node or string +``` + + Coroutine --------- * **Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().** diff --git a/index.html b/index.html index 936ebda..57d44b7 100644 --- a/index.html +++ b/index.html @@ -215,7 +215,7 @@ pre.prettyprint { '3. Syntax': [Args, Inline, Closure, Decorator, Class, Duck_Types, Enum, Exceptions], '4. System': [Print, Input, Command_Line_Arguments, Open, Path, Command_Execution], '5. Data': [CSV, JSON, Pickle, SQLite, Bytes, Struct, Array, MemoryView, Deque], - '6. Advanced': [Threading, Operator, Eval, Introspection, Metaprograming, Coroutine], + '6. Advanced': [Threading, Operator, Introspection, Metaprograming, Eval, Coroutine], '7. Libraries': [Progress_Bar, Plot, Table, Curses, Logging, Scraping, Web, Profile, NumPy, Image, Audio] } @@ -1751,6 +1751,9 @@ lock.release() results = executor.map(lambda x, y: x + y, 'abc', '123') # ('a1', 'b2', 'c3') +

#Operator

from operator import add, sub, mul, truediv, floordiv, mod, pow, neg, abs
 from operator import eq, ne, lt, le, gt, ge
 from operator import and_, or_, not_
@@ -1764,15 +1767,6 @@ product_of_elems = functools.reduce(op.mul, <collection>)
 LogicOp          = enum.Enum('LogicOp', {'AND': op.and_, 'OR' : op.or_})
 last_el          = op.methodcaller('pop')(<list>)
 
-

#Eval

>>> from ast import literal_eval
->>> literal_eval('1 + 2')
-3
->>> literal_eval('[1, 2, 3]')
-[1, 2, 3]
->>> literal_eval('abs(1)')
-ValueError: malformed node or string
-
-

#Introspection

Inspecting code at runtime.

Variables

<list> = dir()      # Names of variables in current scope.
 <dict> = locals()   # Dict of local variables. Also vars().
 <dict> = globals()  # Dict of global variables.
@@ -1854,6 +1848,15 @@ MyMetaClass.__base__ == type      # MyMetaClass is a
 |   str   |             |
 +---------+-------------+
 
+

#Eval

>>> from ast import literal_eval
+>>> literal_eval('1 + 2')
+3
+>>> literal_eval('[1, 2, 3]')
+[1, 2, 3]
+>>> literal_eval('abs(1)')
+ValueError: malformed node or string
+
+

#Coroutine