Python Forum
Feedback on simple 'Mock Up' scripts
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Feedback on simple 'Mock Up' scripts
#6
(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.
Reply


Messages In This Thread
Feedback on simple 'Mock Up' scripts - by fxJoan - Aug-20-2018, 04:30 PM
RE: Feedback on simple 'Mock Up' scripts - by Mekire - Aug-21-2018, 05:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Text Shop Simulator Feedback Dash 5 3,463 Apr-19-2019, 01:08 PM
Last Post: Dash

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020