Other articles

  1. PyCon Recording: Investigating Python Wats

    April 18 2015

    Many of us have experienced a "wat" in Python - some behavior that totally mystifies us. Here is my PyCon talk on Investigating Python Wats, where we uncover some surprising implementation details of CPython, some unexpected consequences of mutability, and details of scope and name resolution.

    tags: speaking pycon python wats

  2. Python Wats: Mutable Default Arguments

    April 25 2014

    Let's look at a common Python wat and try to figure out wat's actually happening!

    We'll define a function, foo, which takes one argument, l, which has the default value of an empty list.

    >>> def foo(l=[]):
    ...     l.append('cat')
    ...     return l

    What happens when we call ...

    tags: python python internals

  3. Python Closures and Free Variables

    April 10 2014

    Today, friends, we will continue to dissect functional programming concepts in Python. We're going to try to figure out what the hell is going on in this chunk of code:

    >>> def make_contains_function(x):
    ...     def contains(s):
    ...             return x in s
    ...     return contains

    What happens when we pass make_contains_function a ...

    tags: python python internals functional programming closures

  4. What's the deal with __builtins__ vs __builtin__

    March 23 2014

    Seriously, what's the difference? When you first fire up the Python interpreter, __builtins__ is in your namespace for free:

    >>> globals().keys()
    ['__builtins__', '__name__', '__doc__', '__package__']
    >>> __builtins__
    <module '__builtin__' (built-in)>

    But it appears to be the __builtin__ module (singular)! If you:

    >>> import __builtin__
    >>> __builtin__ is __builtins__

    Hrm. So they ...

    tags: python builtins hacker school python internals

  5. Page 1 / 2 »