Call A Parameter Of A Function In Another One
I have two function f1 and f2 inside of a class. class Ex(): def f1(self,a): ... def f2(self) print(a) ex = Ex() ex.f1(10) ex.f2() What I want is to get
Solution 1:
There are several ways this could be done. one way would be to make a "setter" in your class:
classEx():
a = None# deafult valuedeffunction_1(self,a):
Ex.a = a
...
deffunction_2(self)
print(Ex.a)
eg:
>>> classfoo:
a = Nonedeff(self, a):
foo.a = a
defb(self):
print(foo.a)
>>> f = foo()
>>> f.f(12)
>>> f.b()
12>>>
However, what i suggest you do instead, is to pass the return value of function_1()
to function_2()
:
classEx():deffunction_1(self,a):
...
...
return a
deffunction_2(self, a)
print(a)
...
...
ex = Ex()
a = ex.function_1()
ex.function_2(a)
Post a Comment for "Call A Parameter Of A Function In Another One"