A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/333888.html below:

Will python never intend to support private, protected and public?

Will python never intend to support private, protected and public? Will python never intend to support private, protected and public?Paul Rubin http
Thu Sep 29 19:51:54 EDT 2005
"Fredrik Lundh" <fredrik at pythonware.com> writes:
> from yourcode import Secret
> 
> class Secret(Secret):
>     def gethidden(self):
>         return self.__hidden

Heh, interesting, and it occurs to me that you could do that by
accident (A inherits from B, and then something imports B and makes an
inheriting class that inadvertently happens to be called A).  I.e. the
name mangling can fail its intended purpose.

# your code:

class Secret:
    def __init__(self):
        self.__hidden = "very secret value"

class Parrot(secret): pass

# my code

from yourcode import Parrot

class Secret(Parrot):  # I'm not aware that you also have a Secret class
   def spam(self, x):
      self.__hidden = zoo(x)   # clobbers yourcode's version of secret

   def eggs(self):             # might inadvertently read your version's
      try:
         return self.__hidden
      except AttributeError:
         self.spam(cached_value)

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4