我想为Zed Shaw的LPTHW制作我自己的RPG角色生成器。作业的一部分是为程序的每个“房间”创建一个新类,比如WelcomeScreen
或{
这是主程序。在
import rooms
class Program(object):
def __init__(self, start):
self.start = start
def run(self):
next_room_name = self.start
while True:
room = getattr(self, next_room_name)
next_room_name = room()
x = rooms.WelcomeRoom()
Program(x.hello_user())
这里是rooms
文件,它试图从中提取内容。在
但是当我用python运行主程序时,它只是注销而不是从rooms
返回函数get_name()
。输出张贴在下面。在
Raymond-Weisss-MacBook-Pro:macgre Raylug$ python macgre.py
*******************************************************************************
Welcome to the
Metamorphosis Alpha Character & Random Encounter Generator
Programmed poorly by Raymond Weiss
*******************************************************************************
Please press enter to continue
Raymond-Weisss-MacBook-Pro:macgre Raylug$
如果我的问题标题不是我想问的,我会提前道歉,作为一个新手,有时不知道该问什么。在
返回的是字符串,而不是函数(或函数结果)。你可能想要这样的东西:
或者
^{pr2}$根据你的计划,我想你可能想要第二个。区别在于第一个返回
get_name
函数,而第二个返回get_name
函数的结果。在相关问题 更多 >
编程相关推荐