【发布时间】:2017-06-27 12:00:16
【问题描述】:
我在两个文件中有以下代码:
操作1.py
class App_Name():
def __init__(self):
self.type_option = ""
def Intro(self):
self.type_option = input("Chose one option: ")
...
start = App_Name()
start.Intro()
menu.py
from operation1 import App_name
aP = App_Name()
if aP.type_option == 1:
do smth
elif aP.type.type_option == 2:
do smth 2
如果我输入 1,我希望从第一个 if 条件运行命令。当我尝试打印App_name.type_option 时,它似乎是空的。如何将aP.type_option 的值传递给 menu.py?
【问题讨论】:
-
option只有 1 个“p”。您正在定义 2 个不同的变量... -
我在这里手动输入代码,没有复制 - 是错字
-
问题:
if aP.type_option == 1:不可能发生:type_option是 python 3 中的字符串。 -
问题 #2:您创建了 2 个单独的实例。你必须在
menu.py中做ap.Intro()
标签: class variables python-3.5