使用此代码时:
import random
class result:
list = ['a', 'b', 'c']
def choicename(self):
for i in list:
if i == list[0]:
result = random.randint(90, 100)
else:
result = random.randint(0, 10)
print 'The %s result is %d' % (i, result)
if __name__ == '__main__':
t = result()
t.choicename()
我得到一个错误:
File "D:\Program\test\test\__init__.py", line 22, in <module>
t.choicename()
File "D:\Program\test\test\__init__.py", line 13, in choicename
for i in list:
TypeError: 'type' object is not iterable
为什么?list
对我来说很合适。
choicename
中的list
表示list
类型。如果你想要result.list
,那就是你需要使用的。相关问题 更多 >
编程相关推荐