我不太清楚如何表达问题的主题......
我有 3 个文件布局:
银行.py:
class Bank(object):
def __init__(self, money):
self.money = money
def currentMoney(self):
print "You currently have $%d" %self.money
def useMoney(self, money_use):
self.money = self.money - money_use
print "You used $%d" %money_use
self.currentMoney()
def getMoney(self, money_get):
self.money = self.money + money_get
print "You received $%d" %money_get
self.currentMoney()
事件.py:
class Event(object):
def Event1(self):
print "Your dad needs money. Will you give him?"
decision = raw_input("Yes or No")
if decision == "Yes":
Bank.useMoney(500)
elif decision == "No":
print "Your father is sad"
else:
print "I do not know what are you talking about"
主要.py:
import bank
import event
Bank = bank.Bank(1000)
Event = event.Event()
Event.Event1()
当我执行代码时。我收到以下错误:
NameError: global name 'Bank' is not defined
基本上,我想做的是使用 event.py 来创建一系列会影响金钱的事件,我可以使用 main.py 来运行不同的系列事件。
你能启发我如何做到这一点吗?谢谢!