Skip to content

Instantly share code, notes, and snippets.

@davidism
Created July 27, 2016 15:03
Show Gist options
  • Save davidism/645100dc43633c02d60f156ef4d0d451 to your computer and use it in GitHub Desktop.
Save davidism/645100dc43633c02d60f156ef4d0d451 to your computer and use it in GitHub Desktop.
class namespace scope
a = 'global'
class Fred:
a = 'class'
b = (a for i in range(10))
c = [a for i in range(10)]
d = a
e = lambda: a
f = lambda a=a: a
@staticmethod
def g():
return a
print(Fred.a) # class
print(next(Fred.b)) # global
print(Fred.c[0]) # class in Python 2, global in Python 3
print(Fred.d) # class
print(Fred.e()) # global
print(Fred.f()) # class
print(Fred.g()) # global
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment