【发布时间】:2011-10-11 10:18:12
【问题描述】:
我无法让两个班级互动。这是我要导入文件 youtest.py 的第一个类的代码:
from youtest import MyTest
class RunIt(object):
def __init__(self):
self.__class__ = MyTest
r = RunIt()
r.iffit()
我正在尝试通过此类运行 MyTest 类(代码如下):
from sys import exit
class MyTest(object):
def death(self):
exit
def iffit(self):
oh_no = raw_input(">")
print "What is your name?"
if oh_no == "john":
print "welcome john"
else:
print "game over"
return 'death'
当我运行它时,我得到以下信息:
文件“youtest.py”,第 19 行 返回“死亡” SyntaxError: 'return' 外部函数
希望这个问题足够清楚,感谢您的帮助。
【问题讨论】:
-
在我查看了您在 SO 的所有问题后,我强烈建议您阅读the tutorial。
标签: python class call return interaction