I want to get access to an variable from function that is inside other class. How can i do it? I've tried multiple "possible" solutions, but I cant still find it out.
class Class(object):
def assign(self):
self.result = 'passed'
print(Class.result)
print(Class.assign().result)
class Class(object):
def assign(self):
self.result = 'passed'
return self.result
object = Class()
print(object.assign())
this code return the self.result
variable
To access the attribute you first need to create an instance of the class, then execute the method in order to create the attribute and finally you can access it:
class Class(object):
def assign(self):
self.result = 'passed'
obj = Class()
obj.assign()
print(obj.result)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.