Initially i thought to do something like:
#EXIT CODES
class ExitCode(object):
(USERHOME_INVALID, \
USERHOME_CANNOT_WRITE, \
USERHOME_CANNOT_READ, \
BASHRC_INVALID) = range(-1, -5, -1)
But than I’ve realized that I’ll have to know exactly the total number of EXIT_CODES, so that I can pass it to the range() function. Let’s suppose I’ll have 87 (arbitrary) EXIT_CODES… I don’t want to count to 87 (not that it’s hard) but I am looking for a more elegant solution.
Any suggestions ?
EDIT:
EXIT_CODE is a negative int that will be passed to sys.exit . Instead of writing the number I prefer to use some sort of constants (something like #defines or enums in C, or enums in Java).
Sounds like what you want is the Python equivalent of an enumeration in C# or other similar languages. How can I represent an 'Enum' in Python? provides several solutions, though they still require the number of items you have.
EDIT: How can I represent an 'Enum' in Python? looks way better.
Or you could try something like this (probably not the best solution, though):