I get an UnboundLocalError when I reimport an already imported module in python 2.7. A minimal example is
#!/usr/bin/python
import sys
def foo():
print
What's hard to understand about this situation is that when you import something inside a scope, there is an implicit assignment. (Actually a re-assignment in this case).
The fact that import sys
exists within foo
means that, within foo
, sys
doesn't refer to the global sys
variable, it refers to a separate local variable also called sys
.