2012-03-18 27 views
-2

ifでプログラムを終了するにはどうすればよいですか?Pythonでプログラムを終了する方法

#some code 
if a == exit: 
    #here should be the program terminated not quit with program (can be with message) 
else: 
    #the rest of the code 

スクリプトを実行しているこれで

sys.exit() 

はプログラムを終了使い方: はここでの例です。 スクリプトを終了するコマンドが必要です。

答えて

0

これは私の仕事です。

def main(): 
    print "Hello" 
    testv=5 
    if testv==6: 
     print "!!!" 
     return 0; 
    else: 
     print "World" 
    print "***********" 
    return 0; 

if __name__ == "__main__": 
    main() 

プログラムが終了するかどうかを調べるためにtestvの値を変更します。

関連する問題