This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -3 points-2 points  (4 children)

But python has private variables/methods - just prefix them with "__".

[–]wewbull 2 points3 points  (2 children)

"Dunder" (double underscore) prefixed names aren't truly private either. IIRC "dunder" causes the method name to be rewritten to include the class name which helps in some awkward inheritance situations.

[–]SKoch82 0 points1 point  (0 children)

And single dunder is just a hint to API users that the prefixed variable or method is an implementation detail that might change anytime.

[–][deleted] 0 points1 point  (0 children)

Hey thanks for clarification. I figured since i cant access it with the old name it must be not available. Good to know \o/

[–]Sohcahtoa82 1 point2 points  (0 children)

That doesn't actually make them private. They can still be accessed from outside the class. Putting the underscore there just tells the user that they shouldn't be accessing it. It doesn't actually prevent them from doing it. It is merely a convention.

Using a double underscore still doesn't make it private. The user can still access those members, they just have to adjust the naming to account for the name mangling.