我遇到了无法解释的错误。有人可以教我吗?
class Base(object):
def __init__(self):
print("Base")
class MyTest(Base):
base = "Test"
data = base+"111" #OK
string_list = [base+str(Value) for Value in range(10)] #Error! Why?
def __init__(self):
super(MyTest, self).__init__()
print(self.string_list)
print(self.data)
MyTest()
我收到什么错误消息
Traceback (most recent call last):
File "Test.py", line 8, in <module>
class MyTest(Base):
File "Test.py", line 11, in MyTest
string_list = [base+str(Value) for Value in range(10)]
File "Test.py", line 11, in <listcomp>
string_list = [base+str(Value) for Value in range(10)]
NameError: name 'base' is not defined