@ -215,7 +215,7 @@ pre.prettyprint {
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '3. Syntax'< / span > < / span > < / strong > : [< a href = "#arguments" > Args< / a > , < a href = "#inline" > Inline< / a > , < a href = "#closure" > Closure< / a > , < a href = "#decorator" > Decorator< / a > , < a href = "#class" > Class< / a > , < a href = "#ducktypes" > Duck_Types< / a > , < a href = "#enum" > Enum< / a > , < a href = "#exceptions" > Exceptions< / a > ],
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '4. System'< / span > < / span > < / strong > : [< a href = "#print" > Print< / a > , < a href = "#input" > Input< / a > , < a href = "#commandlinearguments" > Command_Line_Arguments< / a > , < a href = "#open" > Open< / a > , < a href = "#path" > Path< / a > , < a href = "#commandexecution" > Command_Execution< / a > ],
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '5. Data'< / span > < / span > < / strong > : [< a href = "#csv" > CSV< / a > , < a href = "#json" > JSON< / a > , < a href = "#pickle" > Pickle< / a > , < a href = "#sqlite" > SQLite< / a > , < a href = "#bytes" > Bytes< / a > , < a href = "#struct" > Struct< / a > , < a href = "#array" > Array< / a > , < a href = "#memoryview" > MemoryView< / a > , < a href = "#deque" > Deque< / a > ],
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '6. Advanced'< / span > < / span > < / strong > : [< a href = "#threading" > Threading< / a > , < a href = "#introspection" > Introspection < / a > , < a href = "#metaprograming" > Metaprograming < / a > , < a href = "#operator" > Operator < / a > , < a href = "#eval" > Eval < / a > , < a href = "#coroutine" > Coroutine< / a > ],
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '6. Advanced'< / span > < / span > < / strong > : [< a href = "#threading" > Threading< / a > , < a href = "#operator" > Operator < / a > , < a href = "#eval" > Eval < / a > , < a href = "#introspection" > Introspection < / a > , < a href = "#metaprograming" > Metaprograming < / a > , < a href = "#coroutine" > Coroutine< / a > ],
< strong > < span class = "hljs-string" > < span class = "hljs-string" > '7. Libraries'< / span > < / span > < / strong > : [< a href = "#progressbar" > Progress_Bar< / a > , < a href = "#plot" > Plot< / a > , < a href = "#table" > Table< / a > , < a href = "#curses" > Curses< / a > , < a href = "#logging" > Logging< / a > , < a href = "#scraping" > Scraping< / a > , < a href = "#web" > Web< / a > , < a href = "#profile" > Profile< / a > ,
< a href = "#numpy" > NumPy< / a > , < a href = "#image" > Image< / a > , < a href = "#audio" > Audio< / a > ]
}
@ -1751,6 +1751,28 @@ lock.release()
results = executor.map(< span class = "hljs-keyword" > lambda< / span > x: x + < span class = "hljs-number" > 1< / span > , range(< span class = "hljs-number" > 3< / span > )) < span class = "hljs-comment" > # (1, 2, 3)< / span >
< / code > < / pre > < / div >
< div > < h2 id = "operator" > < a href = "#operator" name = "operator" > #< / a > Operator< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > add, sub, mul, truediv, floordiv, mod, pow, neg, abs
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > eq, ne, lt, le, gt, ge
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > and_, or_, not_
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > itemgetter, attrgetter, methodcaller
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > import< / span > operator < span class = "hljs-keyword" > as< / span > op
sorted_by_second = sorted(< collection> , key=op.itemgetter(< span class = "hljs-number" > 1< / span > ))
sorted_by_both = sorted(< collection> , key=op.itemgetter(< span class = "hljs-number" > 1< / span > , < span class = "hljs-number" > 0< / span > ))
product_of_elems = functools.reduce(op.mul, < collection> )
LogicOp = enum.Enum(< span class = "hljs-string" > 'LogicOp'< / span > , {< span class = "hljs-string" > 'AND'< / span > : op.and_, < span class = "hljs-string" > 'OR'< / span > : op.or_})
last_el = op.methodcaller(< span class = "hljs-string" > 'pop'< / span > )(< list> )
< / code > < / pre >
< div > < h2 id = "eval" > < a href = "#eval" name = "eval" > #< / a > Eval< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-meta" > > > > < / span > < span class = "hljs-keyword" > from< / span > ast < span class = "hljs-keyword" > import< / span > literal_eval
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > '1 + 2'< / span > )
< span class = "hljs-number" > 3< / span >
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > '[1, 2, 3]'< / span > )
[< span class = "hljs-number" > 1< / span > , < span class = "hljs-number" > 2< / span > , < span class = "hljs-number" > 3< / span > ]
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > 'abs(1)'< / span > )
ValueError: malformed node or string
< / code > < / pre > < / div >
< div > < h2 id = "introspection" > < a href = "#introspection" name = "introspection" > #< / a > Introspection< / h2 > < p > < strong > Inspecting code at runtime.< / strong > < / p > < div > < h3 id = "variables" > Variables< / h3 > < pre > < code class = "python language-python hljs" > < list> = dir() < span class = "hljs-comment" > # Names of variables in current scope.< / span >
< dict> = locals() < span class = "hljs-comment" > # Dict of local variables. Also vars().< / span >
< dict> = globals() < span class = "hljs-comment" > # Dict of global variables.< / span >
@ -1832,28 +1854,6 @@ MyMetaClass.__base__ == type <span class="hljs-comment"># MyMetaClass is a
| str | |
+---------+-------------+
< / code > < / pre >
< div > < h2 id = "operator" > < a href = "#operator" name = "operator" > #< / a > Operator< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > add, sub, mul, truediv, floordiv, mod, pow, neg, abs
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > eq, ne, lt, le, gt, ge
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > and_, or_, not_
< span class = "hljs-keyword" > from< / span > operator < span class = "hljs-keyword" > import< / span > itemgetter, attrgetter, methodcaller
< / code > < / pre > < / div >
< pre > < code class = "python language-python hljs" > < span class = "hljs-keyword" > import< / span > operator < span class = "hljs-keyword" > as< / span > op
sorted_by_second = sorted(< collection> , key=op.itemgetter(< span class = "hljs-number" > 1< / span > ))
sorted_by_both = sorted(< collection> , key=op.itemgetter(< span class = "hljs-number" > 1< / span > , < span class = "hljs-number" > 0< / span > ))
product_of_elems = functools.reduce(op.mul, < collection> )
LogicOp = enum.Enum(< span class = "hljs-string" > 'LogicOp'< / span > , {< span class = "hljs-string" > 'AND'< / span > : op.and_, < span class = "hljs-string" > 'OR'< / span > : op.or_})
last_el = op.methodcaller(< span class = "hljs-string" > 'pop'< / span > )(< list> )
< / code > < / pre >
< div > < h2 id = "eval" > < a href = "#eval" name = "eval" > #< / a > Eval< / h2 > < pre > < code class = "python language-python hljs" > < span class = "hljs-meta" > > > > < / span > < span class = "hljs-keyword" > from< / span > ast < span class = "hljs-keyword" > import< / span > literal_eval
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > '1 + 2'< / span > )
< span class = "hljs-number" > 3< / span >
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > '[1, 2, 3]'< / span > )
[< span class = "hljs-number" > 1< / span > , < span class = "hljs-number" > 2< / span > , < span class = "hljs-number" > 3< / span > ]
< span class = "hljs-meta" > > > > < / span > literal_eval(< span class = "hljs-string" > 'abs(1)'< / span > )
ValueError: malformed node or string
< / code > < / pre > < / div >
< div > < h2 id = "coroutine" > < a href = "#coroutine" name = "coroutine" > #< / a > Coroutine< / h2 > < ul >
< li > < strong > Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().< / strong > < / li >
< li > < strong > Coroutines provide more powerful data routing possibilities than iterators.< / strong > < / li >
@ -1981,7 +1981,7 @@ logger.<level>(<span class="hljs-string">'A logging message.'</span>)
< li > < strong > < code class = "python hljs" > < span class = "hljs-string" > '< timedelta> '< / span > < / code > - Max age of a file.< / strong > < / li >
< li > < strong > < code class = "python hljs" > < span class = "hljs-string" > '< str> '< / span > < / code > - Max age as a string: < code class = "python hljs" > < span class = "hljs-string" > '1 week, 3 days'< / span > < / code > , < code class = "python hljs" > < span class = "hljs-string" > '2 months'< / span > < / code > , …< / strong > < / li >
< / ul >
< div > < h2 id = "scraping" > < a href = "#scraping" name = "scraping" > #< / a > Scraping< / h2 > < div > < h4 id = "scrapespythonsurlversionnumberandlogo fromwikipediapage" > Scrapes Python's URL, version number and logo from Wikipedia page:< / h4 > < pre > < code class = "python language-python hljs" > < span class = "hljs-comment" > # $ pip3 install requests beautifulsoup4< / span >
< div > < h2 id = "scraping" > < a href = "#scraping" name = "scraping" > #< / a > Scraping< / h2 > < div > < h4 id = "scrapespythonslogo urland versionnumberfromwikipediapage" > Scrapes Python's logo, URL and version number from Wikipedia page:< / h4 > < pre > < code class = "python language-python hljs" > < span class = "hljs-comment" > # $ pip3 install requests beautifulsoup4< / span >
< span class = "hljs-keyword" > import< / span > requests
< span class = "hljs-keyword" > from< / span > bs4 < span class = "hljs-keyword" > import< / span > BeautifulSoup
url = < span class = "hljs-string" > 'https://en.wikipedia.org/wiki/Python_(programming_language)'< / span >