#-*-coding:utf-8-*-fromsysimportexitclassnewgame(object):def__init__(self,start):self.start=start#self.cccl()defplay(self):next=self.startwhileTrue:print"\n--------"printnextroom=getattr(self,next)next=room()defdeath(self):print"thisisdeath"exit(-1)defcccl(self):print"thisisbbbb"#returnself.al()如果加上return或者exit就成功不加则报错#exit(1)defal(self):print"thisisal"action=raw_input(">")ifaction=='1':return"death"elifaction=='2':return"cccl"ngame=newgame("al")ngame.play()line17,inplayroom=getattr(self,next)TypeError:getattr():attributenamemustbestring请问这是为什么呢?pyenvversionanaconda-2.0.1(setby/usr/local/opt/pyenv/version)但是放到ideone.com上就又不报错了
添加回答
举报
0/150
提交
取消