Let's say I define a class. I have a fun method, where I create self.x. I want to use self.x in a different method (reuse). How could I do that? Because I tried what I wrote and didn't work. Thanks!
class test:
def __init__(self,t):
self.t = t
def fun(self):
self.x = self.t+1
def reuse(self):
self.y = self.x
self.fun()is ever executed,self.xis not defined, so you'll need to ensure thatself.fun()has been called atleast once prior to callingself.reuse()self.fun()doesn't return anything. So you'll just need to addself.fun()before theself.y = self.xself.fun()beforeself.y = self.xit calls theself.fun()every time he callsself.reuse(), which can modify the contents.