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 9246655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:32:33+00:00 2026-06-18T09:32:33+00:00

I want to do something like that: action = :default if some_condition1: action =

  • 0

I want to do something like that:

action = :default

if some_condition1:
    action = :do_something

if some_condition2:
    action = :do_other_thing

...

if action == :default:
   one_reaction()
elif action == :do_something:
   other_reaction()
...

What should I use to represent actions choice?

Variants that come to mind:

  • Create enumeration

    class MyActions:
        DEFAULT=1
        SO_SOMETHING=2
        SO_OTHER_THING=3
    

    inconvenient, need to scroll to and fro and “register” new action choices.

  • Use magic numbers. Not good.

  • Use strings.
  • 1 1 Answer
  • 0 Views
  • 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-06-18T09:32:34+00:00Added an answer on June 18, 2026 at 9:32 am

    “Symbols” in Lisp can be thought of, conceptually, as interned strings.

    action = 'default'
    
    if some_condition1:
        action = 'do_something'
    
    if some_condition2:
        action = 'do_other_thing'
    
    ...
    
    if action == 'default':
       one_reaction()
    elif action == 'do_something':
       other_reaction()
    ...
    

    Whenever you would use a symbol in Lisp, Python would use a string. Lisp has to make a distinction because it is homoiconic, but since Python isn’t homoiconic, the distinction is unnecessary.

    Alternatives

    If you use numbers instead, then you lose REPL-ability. For example,

    default = 1
    do_something = 2
    do_other_thing = 3
    
    >>> x = default
    >>> x
    1 # is 1 default? I can't remember...
    

    There are more sophisticated ways to do this, like creating special classes, but the small benefit is not worth the added complexity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have a route that looks something like: www.abc.com/companyName/Controller/Action/Id However, all the
I want to do something that seems like it should be fairly simple, but
Q1. I want to grep something like that: grep -Ir --exclude-dir=some*dirs my-text ~/somewhere but
What a want to do is something like that: declare @id int set @id
I want to do something like $('a.filter-link').click(function(e) { e.preventDefault(); var that = $(this), categoryId
I want to set layout something like What i thought that i will have
I want something that will receive me the processes details, like I receive with
I want to have a template class that looks something like what I have
I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
I want to know that, is something like this, possible? : #test{ background-color: red;

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.