Опять же на programmingwats.tumblr.com наткнулся на небольшую особенность питона.
my_str_1 = "1: outside of func"
my_str_2 = "2: outside of func"
def func_1():
my_str_1 = "1: inside the func"
my_str_2 = "2: inside the func"
def func_2():
print(my_str_1)
print(my_str_2)
my_str_1 = "1: inside the class"
func_2()
func_1()
prints:
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<stdin>”, line 8, in func_1
File “<stdin>”, line 5, in func_2
UnboundLocalError: local variable ‘my_str_1’ referenced before assignment
my_str_1 = "1: outside of func"
my_str_2 = "2: outside of func"
def func_1():
my_str_1 = "1: inside the func"
my_str_2 = "2: inside the func"
def func_2():
print(my_str_1)
print(my_str_2)
my_str_1 = "1: inside the class"
func_2()
func_1()
prints:
Traceback (most recent call last):
File “<stdin>”, line 1, in <module>
File “<stdin>”, line 8, in func_1
File “<stdin>”, line 5, in func_2
UnboundLocalError: local variable ‘my_str_1’ referenced before assignment