Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1080567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:03:16+00:00 2026-05-16T22:03:16+00:00

Initially i thought to do something like: #EXIT CODES class ExitCode(object): (USERHOME_INVALID, \ USERHOME_CANNOT_WRITE,

  • 0

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).

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:03:16+00:00Added an answer on May 16, 2026 at 10:03 pm

    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):

    class _ExitCode:
        _exit_codes=["EXIT_CODE","EXIT_CODE_TWO"]
        def __getattr__(self, name):
            if name in _ExitCode._exit_codes:
                return -(_ExitCode._exit_codes.index(name)+1)
            raise AttributeError("Exit code %s not found" % name)
    
    ExitCode=_ExitCode()
    print ExitCode.EXIT_CODE #-1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I initially thought that how to pass class attribute and value to markdown syntax
Initially I thought it was a CSS issue but I built a small sample
Initially I thought this was going to work, but now I understand it won't
I'd like to inherit PDOStatement class and use it in my website scripts. But
Initially, I thought I could use :first-letter in CSS, legacy browser support aside, but
I've got a simple form in Django, that looks something like this: class SearchForm(forms.Form):
I initially thought that 64 bit instructions would not work on OS-X 10.5. I
For example: a) int [x][y][z] vs b) int[x*y*z] Initially thought I'd go with a)
My animationDidStop method is not being called for some reason, initially I thought it
I was trying to solve this problem - http://www.spoj.pl/problems/LISA/ I thought of Greedy initially,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.