sys.exit()

Peter Hansen peter at engcorp.com
Thu Oct 9 09:32:28 EDT 2003


Ivan Voras wrote:
> 
> In a code such as:
> 
> if len(sys.argv) < 2:
>     print "I need arguments!"
>     sys.exit(1)
> 
> Is sys.exit() really a good choice? Is there something more elegant? (I
> tried return but it is valid only in a function)

sys.exit() is the proper, defined, cross-platform way to exit from 
a program and return a value to the calling program.  Change your
definition of elegant and you could consider it easily the most elegant
of all solutions. ;-)

-Peter




More information about the Python-list mailing list