python类中的声明等同于_init_?

Cen*_*noc 3 python

我想知道放在python类顶部的声明是否等同于语句__init__?例如

import sys

class bla():
    print 'not init'
    def __init__(self):
        print 'init'
    def whatever(self):
        print 'whatever'

def main():
    b=bla()
    b.whatever()
    return 0

if __name__ == '__main__':
    sys.exit( main() )
Run Code Online (Sandbox Code Playgroud)

输出是:

not init
init
whatever
Run Code Online (Sandbox Code Playgroud)

作为旁注,我现在也得到:

Fatal Python error: PyImport_GetModuleDict: no module dictionary!

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Run Code Online (Sandbox Code Playgroud)

有关为什么会这样的想法?先感谢您!

Mar*_*ers 6

不,这不等同.即使在实例化类型对象之前,也会在定义print 'not init'类时运行该语句.blabla

>>> class bla():
...    print 'not init'
...    def __init__(self):
...        print 'init'
not init

>>> b = bla()
init
Run Code Online (Sandbox Code Playgroud)