Python main call within class

后端 未结 3 1614
盖世英雄少女心
盖世英雄少女心 2021-02-01 16:38

I haven\'t done much python - coming from a C/Java background - so excuse me for asking such a simple question. I am using Pydev in Eclipse to write this simple program, and all

3条回答
  •  臣服心动
    2021-02-01 17:15

    That entire block is misplaced.

    class Example(object):
        def main(self):     
            print "Hello World!"
    
    if __name__ == '__main__':
        Example().main()
    

    But you really shouldn't be using a class just to run your main code.

提交回复
热议问题