What command should be use when the testing of arguments is failed?

Cameron Simpson cs at zip.com.au
Thu Oct 15 03:18:37 CEST 2009

On 14Oct2009 19:58, Peng Yu <pengyu.ut at gmail.com> wrote:
| On Wed, Oct 14, 2009 at 7:57 PM, Joe Riopel <goon12 at gmail.com> wrote:
| > On Wed, Oct 14, 2009 at 8:53 PM, Peng Yu <pengyu.ut at gmail.com> 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.
| >
| > I usually use sys.exit.
| I actually wanted to ask what return code should be returned in this
| case when the arguments are not right. Thank you1

It should be non-zero (0 means "success"). Generally, having lots of possible
values for failure (anything non-zero) lets programs indicate the reason for
the failure. For example, rsync and sendmail have specific exit codes for
specific problems. Most programs don't have or need that degree of detail.
Unless there are special circumstances my own convention is to use 2 for a
usage/wrong-arguments failure and 1 for "this didn't work".

Cameron Simpson <cs at zip.com.au> DoD#743

Don't have awk? Use this simple sh emulation:
    echo 'Awk bailing out!' >&2
    exit 2
- Tom Horsley <tahorsley at csd.harris.com>

More information about the Python-list mailing list