我想通过使instance Outer(variable)指定一次变量,而不是在所有静态类中使用这个变量,我应该怎么做?除了使用非静态方法并将外部传递到每个内部类之外,还有其他解决方案吗?在
class Outer():
def __init__(self, variable):
self.variable= variable
class Inner1():
@staticmethod
def work1():
**print Outer.variable**
class Inner2():
@staticmethod
def work2():
**print Outer.variable**
如果您真的想要这样的东西,元类可能会有所帮助,例如:
那么
^{pr2}$不,内部类方法无法访问外部类的实例。在
相关问题 更多 >
编程相关推荐