Skip to content Skip to sidebar Skip to footer

Why Does Python's Argparse Use An Error Code Of 2 For Systemexit?

When I give Python's argparse input it doesn't like, it raises a SystemExit with a code of 2, which seems to mean 'No such file or directory'. Why use this error code? import argpa

Solution 1:

You are confusing C errnoerror codes with a process exit status; the two concepts are entirely unrelated.

Exit status values have no official standard, but by convention 2 is taken to mean Incorrect usage; this is the exit code used by Bash built-ins, for example.

The os module exposes os.EX_* constants that represent the sysexit.h constants used by many POSIX systems. os.EX_USAGE is exit code 64 and could be used as well, although argparse doesn't actually use this constant as it is only available on UNIX systems while argparse needs to work on Windows and other platforms too.

Post a Comment for "Why Does Python's Argparse Use An Error Code Of 2 For Systemexit?"