python class: store a variable in the class and use it later -


first have i'm not professional python programmer,
might ask stupid questions, please bear me...

here idea:

class foo:     def __init__(self):         self.myvalue = ''     def function1(self, something):         self.myvalue =     def function2(self):         print self.myvalue  foo = foo() foo.function1("target") --> want store value "target" in class , use later foo.function2()  --> want print out "target" 

obviously, wrong, don't know how how correct it.

if can give me directions, i'll appreciate it!

you can can try take @ @property decorator:

class foo(object):      def __init__(self):         self._myvalue = none      @property     def myvalue(self):         print self._myvalue         return self._myvalue      @myvalue.setter     def myvalue(self, something):         self._myvalue =  foo = foo() foo.myvalue = 10 foo.myvalue 

find more on here real world example how use property feature in python?


Comments