首先,我不得不说,我不是一个专业的Python程序员,
所以我可能会问一些很笨的问题,请与我...Python类:存储在类中的变量,并在以后使用它
这里的理念是:
class Foo:
def __init__(self):
self.myValue = ''
def function1(self, something):
self.myValue = something
def function2(self):
print self.myValue
foo = Foo()
foo.function1("target") --> I want to store the value "target" in the class and use it later
foo.function2() --> I want to print out "target"
显然,这是真的错了,但我不知道如何如何纠正它。
如果你能给我一些指导,我会非常感激!
将'self.Value'更改为'self.myValue'。 – 2013-03-27 03:05:46
你快到了。在所有方法中拼写相同,然后重试。 – SingleNegationElimination 2013-03-27 03:07:11
谢谢,我改变了它。 – amigcamel 2013-03-27 03:09:08