What is the benefit of private name mangling in Python? -


python provides private name mangling class methods , attributes.

are there concrete cases feature required, or carry on java , c++?

please describe use case python name mangling should used, if any?

also, i'm not interested in case author merely trying prevent accidental external attribute access. believe use case not aligned python programming model.

it's partly prevent accidental internal attribute access. here's example:

in code, library:

class yourclass:     def __init__(self):         self.__thing = 1           # private member, not part of api 

in code, in i'm inheriting library class:

class myclass(yourclass):     def __init__(self):         # ...         self.__thing = "my thing"  # private member; name coincidence 

without private name mangling, accidental reuse of name break library.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -