我试图在__Team
类的构造函数中创建一个__Profile
类的实例,但我无法访问__Profile
。我应该怎么做?python - 嵌套类访问修饰符
这是我的代码
class SlackApi:
# my work
class __Team:
class __Profile:
def get(self):
# my work
def __init__(self, slackApi):
self.slackApi = slackApi
self.profile = __Profile()
self.profile = __Team.__Profile()
self.profile = SlackApi.__Team.__Profile()
# I tried to all of these case, but I failed
# I need to keep '__Team', '__Profile' class as private class
我的Python版本是3.5.1
为什么使用嵌套类和'__mangled_names'呢? *“我需要保留'__Team','__Profile'类作为私人类”* - 为什么? – jonrsharpe
当您尝试以不支持它们的语言实现访问修饰符(或任何其他功能)时,您会实现两件事:1)您得不到令人满意的结果; 2)您不从语言的功能中受益支持。这有点像在自行车上滑雪:比滑雪还差,比骑自行车还糟糕。 – zvone