Skip to content

Instantly share code, notes, and snippets.

@naiquevin
Last active August 29, 2015 14:09
Show Gist options
  • Save naiquevin/4a44d8ad8bfc55127d29 to your computer and use it in GitHub Desktop.
Save naiquevin/4a44d8ad8bfc55127d29 to your computer and use it in GitHub Desktop.
Python scoping
import d
x = 10
def f(n):
return x + n
print 'f(2) called directly in module a [a.x = 10]'
print f(2)
print 'f(2) called indirectly in module a by passing to d.h [d.x = 1000]'
print d.h(f)
import a
x = 100
def g(func):
return func(2)
print 'a.f(2) called indirectly in module b by passing it to g [b.x = 100]'
print g(a.f)
import b
import a
print 'a.f(2) called indirectly in module c by passing it to b.g [no c.x]'
print b.g(a.f)
x = 1000
def h(func):
return func(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment