如果是在同一个 module中(也就是同一个py 文件里),直接用就可以 如果在不同的module里,例如 a.py里有 class A: b.py 里有 class B: 如果你要在class B里用class A 需要在 b.py的开头写上 from a import A #mymodel.py import matplotlib.pyplot as plt class test(object): num = [] def __init__(self, _list): super(test, self).__init__() self.num = _list def prt(self): print(self.num) def tplt(self): plt.plot(self.num) plt.show() #mian.py from mymodel import test mylist= [1,2,3] a = test(mylist) a.prt() a.tplt()
|