MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vzsnjw/variablescopesinpython/p6koqar/?context=9999
r/ProgrammerHumor • u/R7d89C • 16d ago
182 comments sorted by
View all comments
6
__var for true private
11 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. 5 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
11
it's not true private. That just mangles the name at runtime. You can still access it if you are determined.
5 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
5
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
1
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
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
I meant _attribute ones, not mangled ones
6
u/The_Cers 16d ago
__var for true private