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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -