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
x = 10
def f(n):
return x + n
print 'f(2) called directly in module a [x = 10]'
print f(2)
import a
x = 100
def g(func):
return func(2)
print 'a.f(2) called indirectly in module b by passing it to g [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'
print b.g(a.f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment