[Tutor] Exit from program early

Johan Geldenhuys johan at accesstel.co.za
Fri Nov 4 08:16:03 CET 2005


Try using 'sys.exit()' where you want the script to stop if you haven't 
supplied enough arguments.
in you example, it looks like it will go on to the else anyway AND print 
the string at the end.

HTH,
Johan


Roy Bleasdale wrote:

>Hi
>
>In the example below I would like the program to stop if I forgot to 
>provide an argument . Though I could do all my processing indented under 
>the else statement, I was wondering if there was a command that would allow 
>me to halt the program execution early.
>
>Regards,
>
>Roy
>
>
># Example program - Test for valid argument
>
>import sys
>
>if len(sys.argv) < 2:
>     print "opps missing an argument"
>     # Nice if I could stop and exit program here
>else:
>     print "Argument provided!!"
>     # Looking good so go do some stuff
>
>print "Done some stuff"
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>  
>


More information about the Tutor mailing list