How to extend inner classes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kay Schluehr

    #1

    How to extend inner classes?

    You can define a class variable Pos with the class Pos as its value

    class PeriodicGrid :
    class Pos:
    pass
    Pos = Pos
    [color=blue][color=green][color=darkred]
    >>> grid = PeriodicGrid()
    >>> grid.Pos()[/color][/color][/color]
    <__main__.Pos instance at 0x00EEFAD0>

    Ciao
    Kay





  • Alex Martelli

    #2
    Re: How to extend inner classes?

    Kay Schluehr <kayschluehr@gm x.de> wrote:
    [color=blue]
    > You can define a class variable Pos with the class Pos as its value
    >
    > class PeriodicGrid :
    > class Pos:
    > pass
    > Pos = Pos
    >[color=green][color=darkred]
    > >>> grid = PeriodicGrid()
    > >>> grid.Pos()[/color][/color]
    > <__main__.Pos instance at 0x00EEFAD0>[/color]

    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

    Comment

    Working...