OO in Python? ^^

Alex Martelli aleax at mail.comcast.net
Sun Dec 11 15:53:34 EST 2005


Paul Boddie <paul at boddie.org.uk> wrote:
   ...
> offer some kind of solution to that problem. Moreover, Python also lets
> you define double-underscore attribute names which behave give instance
> attributes privacy in all respects, being invisible to users of the
> instances concerned, accessible only within methods belonging to the
> defining class, and safely overloadable in subclasses without incurring
> conflicts.

Unfortunately, that depends on the subclasses' naming:

in module bah.py:
    class Foo(object) ...

in module zot.py:
    import bah
    class Foo(bah.Foo) ...

and alas, the "privacy in all respects" breaks down.  Now, the idea of
"class Foo(bah.Foo)" may look silly with such artificial names, but it
IS somewhat likely to happen in the real world when the classes' names
are meaningful.  I guess pychecker or the like might check for this and
issue a warning if needed... but I do wish we had better ways to prevent
accidental naming conflicts (not that I can easily think of any).


Alex



More information about the Python-list mailing list