python - nested class access modifier
<p>I'm trying to make an instance of a <code>__Profile</code> class in the constructor of the <code>__Team</code> class, but I can't get access to <code>__Profile</code>. How should I do it?</p>

<p>This is my code</p>

<pre><code>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
</code></pre>

<p>My python version is 3.5.1</p>

<p>Python does not have access modifiers. If you try to treat <code>__</code> like a traditional <code>private</code> access modifier, this is one of the problems you get. Leading double underscores cause name mangling - a name <code>__bar</code> inside a <code>class Foo</code> (or <code>class __Foo</code>, or any number of leading underscores before <code>Foo</code>) will be mangled to <code>_Foo__bar</code>.</p>

<p>If you really want to keep those leading double underscores, you'll have to explicitly mangle the names yourself:</p>

<pre><code>self.profile = SlackApi._SlackApi__Team._Team__Profile()
</code></pre>

<p>This is also how you would access the <code>__Profile</code> class from outside of <code>SlackApi</code> altogether, so you're basically bypassing any pretense that these things are private.</p>

python nested private python-3.5