static python classes ?

Ant antroy at
Tue Jun 19 14:32:29 CEST 2007

It's not clear what you mean here. If you mean something like static
inner classes in Java, then you can simply nest classes in Python:

>>> class A(object):
...   class B(object):
...      def aaa(self):
...                                 print "AAAAAA"
>>> z = A.B()

(In contrast the equivalent of Java's ordinary inner class:
>>> class A(object):
...     def __init__(self):
...         class B(object):
...             def aa(self):
...                 print "BBBB"
...         self.B = B
>>> A().B().aa()


If you mean "static class" as in an class which only has static
methods and variables, then the python equivalent is a module.

> I'm new to python, and I can't seem to find in the docs how to create
> the python equivalent of what's called in most OOP languages "static
> classes", can you give me a hint ?

Hope the above was what you are looking for.


More information about the Python-list mailing list