我已经接受了 Rohan 提供的答案并提出了以下内容。它似乎有效,尽管可能有更好/首选的方法来实现这一点。
以下代码允许我跨多个类和方法跟踪帐户余额。
import os
class Foo():
def __init__(self):
self.stored_end = 0
def account(self, a, b):
c = float(a) + b
print a
print b
print c
self.stored_end = c
print self.stored_end
def testy(self, q, v):
print "\n"
print " _ " * 10
z = float(q) + v
print self.stored_end
self.stored_end = self.stored_end + z
print " _ " * 10
print self.stored_end
class Bar():
def __init__(self):
pass
def zippy(self, a, b):
print " _ " * 10
print "this is zippy"
foo.testy(a, b)
class Baz():
def __init__(self):
pass
def cracky(self, g, m):
y = g + m
print " _ " * 10
print "calling stored_end"
foo.stored_end = foo.stored_end + y
print " _ " * 10
print "this is cracky"
print "y = %r" % y
print foo.stored_end
os.system("clear")
foo = Foo()
foo.account(5, 11)
foo.testy(100, 100)
bar = Bar()
bar.zippy(10, 100)
baz = Baz()
baz.cracky(1000, 1)