擅长:python、mysql、java
<p>这里有一个替代方案
pack.py</p>
<pre><code>class One:
def __init__(self):
self.number = 100
def test(self):
print('test')
class Two:
def sample(self):
print('Sample')
</code></pre>
<p>另一个</p>
<pre><code>from pack import *
class Three:
def four(self):
self.obj = One().number
return self.obj
three = Three().four()
print(three)
</code></pre>
<p>按照您的方法,您使用类来访问变量。最好在构造函数中实例化变量(<strong>init</strong>类<strong>One</strong>中的方法)。然后导入该类并在另一个文件的另一个类中访问它</p>
<p>此外,以大写字母开头命名类也是一种很好的做法。有更多可能的方法,但希望能有所帮助</p>