1
Python版本
蟒蛇-V 的Python 2.7.9 ::蟒蛇2.0.1(x86_64的)使用GETATTR()無返,以下錯誤:GETATTR():屬性名稱必須是字符串
沒有回報或退出它得到的錯誤:
line 16, in play room = getattr(self, next) TypeError: getattr(): attribute name must be string
但ideone.com網上其確定
#-*-coding:utf-8-*-
from sys import exit
class newgame(object):
def __init__(self, start):
self.start = start
#self.cccl()
def play(self):
next = self.start
while True:
print "\n--------"
print next
room = getattr(self, next)
next = room()
def death(self):
print "this is death"
exit(-1)
def cccl(self):
print "this is bbbb"
#return self.al()
#exit(1)
def al(self):
print "this is al"
action = raw_input("> ")
if action == '1':
return "death"
elif action == '2':
return "cccl"
ngame = newgame("al")
ngame.play()
哦,我知道了,謝謝 而Ture: – poone