Skip to content

Instantly share code, notes, and snippets.

@lihaoyi
Created November 14, 2015 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lihaoyi/afba78026a1e9a00152a to your computer and use it in GitHub Desktop.
Save lihaoyi/afba78026a1e9a00152a to your computer and use it in GitHub Desktop.
>>> class Foo:
... x = 1
... y = (x, lambda: x)
...
>>> Foo().x
1
>>> Foo().y
(1, <function <lambda> at 0x10754d0c8>)
>>> Foo().y[0]
1
>>> Foo().y[1]
<function <lambda> at 0x10754d0c8>
>>> Foo().y[1]()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in <lambda>
NameError: global name 'x' is not defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment