Jethro's Braindump

Python

Python is an interpreted, general-purpose, high-level programming language. Some properties of Python include:

  • whitespaces being significant
  • dynamically-typed
  • garbage-collected

Python Import Resolution

Say you have a Python import statement:

import abc

Python will look up the following in order:

  1. sys.modules: this is the cache containing previously imported modules
  2. built-in modules
  3. sys.path: Usually includes the current directory

Python Default Parameter Values

source
Default Parameter Values in Python

Python has interesting behaviour for default values:

  def a(v=[]):
      v.append(1)
      print(v)

  a()
  a()
  a()
  a()

Why does this happen? Default parameter values are always evaluated when, and only when, the “def” statement they belong to is executed. Also note that “def” is an executable statement in Python, and that default arguments are evaluated in the “def” statement’s environment. If you execute “def” multiple times, it’ll create a new function object (with freshly calculated default values) each time.

TODO Python Decorators

Books

TODO Fluent Python

TODO Effective Python

TODO High Performance Python