Python - modrpc/info GitHub Wiki
- Python 3.6 documentation: https://docs.python.org/3/
- Python 2.7 documentatoin: https://docs.python.org/2/
- Language guide
- descriptor HOWTO: https://docs.python.org/2/howto/descriptor.html
- aka Python Data Analysis Library
- Python Developer's Guide
- Extending and Embedding the Python Interpreter
- Python/C API Reference Manual
- Green Tree Snakes - the missing Python AST docs
- Eli Bendersky's Python Internals series
- Yaniv Aknin's Python Innards series
- Allison Kaptur's Python Internals Series
- Allisn Kaptur's Python Internals Series2
- Python Compiler Internals, by Thomas Lee
- How Fast Can We Make Interpreted Python, by Russel Power and Alex Rubinsteyn
- Python Attributes and Methods
- Understanding Python by breaking it
pip install -r requirements.txt
- https://pip.pypa.io/en/stable/reference/pip_install/#requirements-file-format
def countdown(n):
try:
while n > 0:
yield n
n -= 1
return
except GeneratorExit: #when user calls close()
return
>>> c = countdown(10)
-
generator: a function that produces a sequence of values for use in iteration
-
countdown(10)
below returns a generator object -
c.next()
will execute statements until it reaches ayield
statement -
c.close()
will shutdown the generator, which is no longer used
-
def receiver():
while True:
n = (yield)
print("Got %s", % n)
-
coroutine: a function which uses yield for its value
- more like a consumer (opposite of generator) but the execution behavior is quite similar to generator
- PEP380 yield from: https://www.python.org/dev/peps/pep-0380/
- details: including scheduler: http://www.cosc.canterbury.ac.nz/greg.ewing/python/yield-from/yield_from.html
- python-yield-scheduler
- A web crawler with asyncio coroutines: http://www.aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html
- David Beazley's key note PyCon'15: https://www.youtube.com/watch?v=lYe8W04ERnY
- async-await in 3.5: https://snarky.ca/how-the-heck-does-async-await-work-in-python-3-5
- asyncio from inside out: http://www.buzzcapture.com/en/2014/05/python-asyncio-inside/
- Python equvalient of goroutine
- Combining console input with event loop: http://stackoverflow.com/questions/29081929/prompt-for-user-input-using-python-asyncio-create-server-instance/
- goless: Go-Style Python: http://goless.readthedocs.io/en/latest/#
- asyncio complete guide
- decorated with
@asyncio.coroutine
- two types of coroutines:
- callee: the function definition itself (
iscoroutinefunction()
) - call instance: the object objtained by calling a coroutine function (
iscoroutine()
)
- callee: the function definition itself (
- inside coroutine body, it can do:
-
result = yield from future
: suspends this coroutine until the future is done -
result = yield from coroutine
: wait for another coroutine to produce a result (or raise exception); it must be call to another "coroutine" return expression
raise exception
- yield from == await
-
- pickle: https://docs.python.org/3/library/pickle.html -- python-proprietary binary format
- json encoder/decoder: https://docs.python.org/3/library/json.html -- text format
- marshal: https://docs.python.org/3/library/marshal.html
- not a general persistence/serialization format -- only for pyc (bytecode); use pickle/shelve instead;
>>> dis.dis(py34_coro)