Inner classes

Samuele Pedroni pedroni at inf.ethz.ch
Wed Jun 13 15:26:24 EDT 2001


Andrew Kuchling wrote:

> xyzmats at laplaza.org (Mats Wichmann) writes:
> > Nonetheless, I was challenged by someone to describe how it isn't a
> > shorcoming in Python that classes don't work this way and didn't
> > convince the guy so I'm looking for a more erudite comparison.
>
> Work *what* way?  It's perfectly legal to do this:
>
> class C:
>     class inner:
>         ... stuff for inner class
>     ... stuff for class C
>
> --amk

Yes, but that's basically a static inner class, you can do

C().inner() but the created inner instance will not contain any
implicitly created reference to the C instance.

To have that you must be explicit:
c=C()
i=C.inner(c)

OTOH python has 1st class functions and most of time with lambdas,
bounded method, etc you can
achieve the same (even in a less verbose way). Jython design supports
and jython coding practice
shows that.

regards.




More information about the Python-list mailing list