You set it in one method and then look it up in another:
class TestClass(object):
def current(self, test):
"""Just a method to get a value"""
self.test = test
print(test)
def next_one(self):
"""Trying to get a value from the 'current' method"""
new_val = self.test
print(new_val)
As a note, you will want to set self.test
before you try to retrieve it. Otherwise, it will cause an error. I generally do that in __init__
:
class TestClass(object):
def __init__(self):
self.test = None
def current(self, test):
"""Just a method to get a value"""
self.test = test
print(test)
def next_one(self):
"""Trying to get a value from the 'current' method"""
new_val = self.test
print(new_val)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…