Private variable and @property in variable inspector on PyCharm

Hi, I would like to know why PyCharm automatically instantiate my private variable when I want to instantiate them with @property.

For example:

class Foo:

    def __init__(self):

        variable_ = []



    def variable(self):

        if len(self.variable_) == 0:

            self.variable_ = [1,2,3,4]

        return self.variable.copy()


If I run my code and instantiate the class, I will see that my variable_ = [1,2,3,4] even if I did not call the variable setter.

So, I wanted to know why it is not variable_ = []


Thank you very much for your help !

Comment actions Permalink

Just a quick correction

>I would like to know why PyCharm automatically

I'm pretty sure it's a python question, not PyCharm.

Comment actions Permalink

The variable is visible within the variable inspector.

In the python console, it shows an empty list if I am not navigating through the variable inspector.


Please sign in to leave a comment.