Python中静态方法可以访问类定义的字典么
展开全部
class MyClass:
class_dict = {}
def __init__(self):
self.value2 = 2
@staticmethod
def static():
static_dict = {}
print(static_dict)
print(self.class_dict) #此处无法执行 NameError: name 'self.class_dict' is not defined
#很遗憾,不可以
sc = MyClass()
sc.static()
class_dict = {}
def __init__(self):
self.value2 = 2
@staticmethod
def static():
static_dict = {}
print(static_dict)
print(self.class_dict) #此处无法执行 NameError: name 'self.class_dict' is not defined
#很遗憾,不可以
sc = MyClass()
sc.static()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询