-
-
Save naiquevin/4a44d8ad8bfc55127d29 to your computer and use it in GitHub Desktop.
Python scoping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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