sys.exit()

Donn Cave donn at drizzle.com
Thu Oct 9 23:51:50 EDT 2003


Quoth "Ivan Voras" <ivoras at fer.hr>:
| 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)

Your question has already been answered many times over, so I will
instead note something about the above that is rather common but
wrong.  "print" writes to sys.stdout (unless instructed otherwise),
and in the present case this output should certainly go to sys.stderr.
The easiest way to do that in recent versions of python (2.0 and
later) is "print >> sys.stderr".

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list