[Tutor] Exit from program early
Hugo González Monteverde
hugonz-lists at h-lab.net
Fri Nov 4 20:11:08 CET 2005
Johan Geldenhuys wrote:
> 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.
> Roy Bleasdale wrote:
>>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.
>># Example program - Test for valid argument
>>if len(sys.argv) < 2:
>> print "opps missing an argument"
>> # Nice if I could stop and exit program here
>> print "Argument provided!!"
>> # Looking good so go do some stuff
>>print "Done some stuff"
>>Tutor maillist - Tutor at python.org
> Tutor maillist - Tutor at python.org
More information about the Tutor