#-*-coding:utf8-*-
class test1():
"""docstring for test1"""
def __init__(self):
self.a=0
self.b=0
self.test1()
def test1(self):
self.a=1
self.b=2
test = test1()
def test2():
c=3
d=c+test.a
print (d)
test2()
Initialization can be placed where you want to call it, and the test1() method is called by default during initialization, so that the data can be accessed through the class object.
First of all, your demand is impossible and unreasonable. It is impossible for two separate functions to access the variables inside each other
You can do it if you use closures, but I don’t know if that’s what you want:
You can encapsulate test1 into a class
Initialization can be placed where you want to call it, and the test1() method is called by default during initialization, so that the data can be accessed through the class object.
You can let test1 use return to return the values of a and b:
Haha, they are all talents, closure, class sealing, clear return, each of the above is an independent solution.