Created
June 16, 2011 06:46
-
-
Save saghul/1028793 to your computer and use it in GitHub Desktop.
Name binding and UnboundLocalError
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
from application.system import host | |
class Foo(object): | |
def __init__(self, host_ip=None): | |
self.host_ip = host_ip or host.default_ip | |
for host in range(10): | |
print host | |
f = Foo() | |
print f.host_ip | |
# Error given by the above code | |
# | |
#Traceback (most recent call last): | |
# File "bogus_scope.py", line 11, in <module> | |
# f = Foo() | |
# File "bogus_scope.py", line 7, in __init__ | |
# self.host_ip = host_ip or host.default_ip | |
#UnboundLocalError: local variable 'host' referenced before assignment | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment