Python - modrpc/info GitHub Wiki

Table of Contents

Overview

Essential Tools, Packages

Anaconda

IPython and Jupyter

matplotlib

NumPy

pandas

  • aka Python Data Analysis Library

SciPy

scikit-learn

statsmodels

Python Development

Python Internals

Python Documentation

Blog Post Series

Other Various Blog Posts and Papers

Requirements file

Language Basics

Generators and yield

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 a yield statement
    • c.close() will shutdown the generator, which is no longer used

Coroutines and yield expressions

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

Concurrency

asyncio

coroutines

  • 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())
  • 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

More Libraries

Persistence

Serialization

Misc Tips

Show bytecode

>>> dis.dis(py34_coro)
⚠️ **GitHub.com Fallback** ⚠️