python中的静态内部类

Abh*_*pta 8 python oop static inner-classes static-classes

我的代码需要有一个内部类,我想创建这个内部类的实例而不创建外部类的实例.
如何在python中这样做?在java中我们可以将内部类定义为静态但我不知道如何在python中使内部类静态化.我知道对于方法我们可以使用@staticmethod装饰器.

class Outer:
    def __init__(self):
        print 'Instance of outer class is created'

    class Inner:
        def __init__(self):
            print 'Instance of Inner class is created'
Run Code Online (Sandbox Code Playgroud)

use*_*690 7

Inner类是在类Outer的定义期间定义的,之后它存在于类的命名空间中.所以只是Outer.Inner().