Peng Yu wrote:
I have the following python code snippet. I'm wondering what command I
should use to terminate the program if the arguments are not right.
#!/usr/bin/env python
import sys
import os
if len(sys.argv) <= 1:
print "usage:", os.path.basename(sys.argv[0]), '<something>'
return ## what command should be used here to terminate the program?
Any non zero value (usually -1) will do the trick thrown with a sys.exit;
By the way, if you are so worried about this kind of detail, you should
check out http://docs.python.org/library/optparse.html.
Then you'll get easily a GNU/POSIX syntax for you program.
Yet if you don't want to use it, at least read the 16.4.2.8 section,
where a common way to handle option/argument issues is described.
JM
--
http://mail.python.org/mailman/listinfo/python-list