我有一个文件x.py
和另一个文件y.py
我在x.py
中有一个类x
,它的函数定义如下:
@property
def x(self):
return self._x
@x.setter
def x(self, x):
self.update_x(x)
def xy(self, l):
self._x = 100
现在我想在另一个文件中使用这个值y.py
我有:
from models.x import X # where X is the name of the class in x.py
def functionX(self):
y = # set this value as the value of x in function x from x.py
我该怎么做?你知道吗
类没有属性
x
。它所拥有的是一个属性方法x
,并且方法只能在实例上调用(大多数情况下是这样)。你可以签出class methods and static methods,但它们不是你想要的)。你知道吗所以在
y.py
中,需要类X
的实例,可以通过执行foo = X()
之类的操作来获得。然后可以参考foo.x
。你知道吗相关问题 更多 >
编程相关推荐