2013-12-11 45 views
1

當我運行python filename.py時,它不會提示輸入或打印輸出。我必須運行什麼命令來運行Base1()類?如何使用python file.py從命令行運行類?

class Base(TestCase): 

    def setUp(self): 
     #prompts for inpt 
     ...... 

class Base1(Base): 

    def base1(self): 
     print('.......') 
     return x 

    def base2(self): 
     output = Base1.base1(self) 
     print(output) 

回答

4

您的程序必須包含一些在命令行運行程序時將執行的頂級語句(即不縮進)。

class Base(TestCase): 

    def setUp(self): 
     #prompts for inpt 
     ...... 

class Base1(Base): 

    def base1(self): 
     print('.......') 
     return x 

    def base2(self): 
     output = Base1.base1(self) 
     print(output) 

# These commands will be executed when "python filename.py" is run from a shell 
foo = Base1() 
foo.base1() 
.... 
+0

好奇-1 downvote做了主要作用。我有什麼問題嗎? –

5

什麼qwrrty建議將工作,但我會建議把它在這蟒蛇是由

def main(): 
    foo = Base1() 
    foo.base1() 

if __name__ == "__main__": 
    main()