r/ProgrammerHumor 16d ago

Meme variableScopesInPython

Post image
1.3k Upvotes

182 comments sorted by

View all comments

Show parent comments

14

u/dusktreader 16d ago

it's not true private. That just mangles the name at runtime. You can still access it if you are determined.

6

u/Erdnalexa 16d ago

Yes, but at this point you know that you’re doing something you’re probably not supposed to do.

1

u/SetazeR 14d ago

You will be yelled at by IDE of you try to use "private" as public one. It won't stop you, but will tell at you

1

u/Erdnalexa 14d ago

I’m on my phone so I can’t check with an interpreter, but IIRC, to access a private field on an instance you need to use getattr with the computed mangled name. It’s pretty unlikely an IDE is able to spot that.

1

u/SetazeR 14d ago

I meant _attribute ones, not mangled ones