python installations on the same system, each with its own set of packages. Invaluable in any python dev machine. virtualenv - http://www.virtualenv.org/en/latest/ virtualenvwrapper - http://virtualenvwrapper.readthedocs.org/en/latest/index. html Make using virtualenv even easier. • Central location of all virtual environments • switch virtual environments with the `workon` command, includes TAB completion
a python installation. Changes made to your sources are immediately available in the Python installation. ProjectB (depends on ProjectA) (virtualenv) for Project B ProjectA
except ObjectNotFound: log(“Object with pk: {} not found”.format(pk)) try: db_object = get_db_object(pk) except ObjectNotFound: log(“Object with pk: {} not found”.format(pk)) else: parent_object = get_object(o.parent_id) • Don’t catch the wrong exceptions • Readability - “do this only when the exception is not raised” vs
{‘name’: ‘Bob’, ‘age’: 5}] ages = [] for kid in kids: ages.append(kid[‘age’]) do_something(ages) do_something([kid['age'] for kid in kids]) • Clear and concise syntax when working with lists (and other iterables) • Readability? Not when it gets too complex
x = (n for n in range(1000000000)) Pros • No extra storage is created • You can then iterate over only part of the list without the extra memory overhead • Cons: • You can only iterate over the result once vs
call_some_other_function() # s to step into result += 1 # n to step over return result Debugging pdb/ipdb Python Debugger Cheatsheet - http://nblock.org/2011/11/15/pdb-cheatsheet/