Class in class

Fredrik Lundh fredrik at pythonware.com
Mon Sep 6 06:07:03 EDT 1999


Gurvijay Singh Bhatti <khalsa at acay.com.au> wrote:
> Like C++ and Java, is it possible to declare a class in a class?

yes.

> If it is then could you tell how?

class foo:
    class bar:
        pass

object = foo.bar()

however, since all followup questions asking
about NameError exceptions will be answered
with "don't use nested classes", you probably
don't want to things this way.  as always, Python
works better if you use it to write Python code ;-)

</F>





More information about the Python-list mailing list