"Fredrik Lundh" <[EMAIL PROTECTED]> 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)
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to