How to extend inner classes?

Kay Schluehr kayschluehr at gmx.de
Sun Nov 28 10:17:01 EST 2004


>>/ You can define a class variable Pos with the class Pos as its value
/>>/ 
/>>/ class PeriodicGrid :
/>>/     class Pos:
/>>/       pass            
/>>/     Pos = Pos 
/>>/ 
/>>/ >>> grid = PeriodicGrid()
/>>/ >>> grid.Pos()
/>>/ <__main__.Pos instance at 0x00EEFAD0>
/
> You can, but that 'Pos = Pos' statement in this code is just as
> redundant and useless as it appears.  In every aspect, the behavior will
> be exactly identical if you remove that assignment.

> Alex

*sigh* 

It's a matter of good i.e. bad taste. Ususally I prefer constructs like this:

class Pos:
    class Pos:
        def __init__(self):
            self.__dict__ = Pos.__dict__
    Pos = staticmethod(Pos)

and spread them all over my code thinking they are genuine Pythonic
with the emphasis of the original meaning of the word and for sake of the
great ancestors. I call them "strange idiom" idioms and they are
made for torturing mankind. If a believing christ would ask me why i do so
the answer would be: calling the animal and accelerating judgement day.

Bye and have a nice Sunday afternoon

Kay







More information about the Python-list mailing list