(Aug-20-2018, 11:45 PM)fxJoan Wrote: Have I used double underscores?No you didn't.
Names like this
__something__
are called dunder methods. You shouldn't be creating your own brand new dunder methods but you will need to use them and define their function bodies like __init__
and such.This isn't what I was talking about though. I was referring to names like this
__something
. This triggers what is called name mangling. Name mangling does just that; screws up the variable name in a predictable (but extremely annoying) way. Every time I need to deal with a name mangled variable I have to look up how it gets mangled but there is nothing stopping me from accessing it. The main purpose is to avoid potential collisions not enforce privacy.https://docs.python.org/2/tutorial/class...references
Single leading underscore variables are used to "mark" variables as private but this is purely documentation. A leading underscore tells another python programmer that they really shouldn't access that variable directly and if they do stuff might break. Also for completeness if you were to star import a file (which you should almost never do), names that started with a single underscore would not be imported.