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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:07:30+00:00 2026-05-25T10:07:30+00:00

I am a RoR programmer new to Python. I am trying to find the

  • 0

I am a RoR programmer new to Python. I am trying to find the syntax that will allow me to set a variable to a specific value only if it wasn’t previously assigned. Basically I want:

# only if var1 has not been previously assigned

var1 = 4
  • 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-05-25T10:07:30+00:00Added an answer on May 25, 2026 at 10:07 am

    This is a very different style of programming, but I always try to rewrite things that looked like

    bar = None
    if foo():
        bar = "Baz"
    
    if bar is None:
        bar = "Quux"
    

    into just:

    if foo():
        bar = "Baz"
    else:
        bar = "Quux"
    

    That is to say, I try hard to avoid a situation where some code paths define variables but others don’t. In my code, there is never a path which causes an ambiguity of the set of defined variables (In fact, I usually take it a step further and make sure that the types are the same regardless of code path). It may just be a matter of personal taste, but I find this pattern, though a little less obvious when I’m writing it, much easier to understand when I’m later reading it.

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

Sidebar

Related Questions

let's say that RoR development environment is set up and working does the developer
I am developing RoR application that works with legacy database and uses ActiveScaffold plugin
In the installation documentation to RoR it mentions that there are many limitations to
I'm still new to ROR, so pardon the simplicity of the question... So http://www.example.com/controller/:id
How do I name a browser window in ROR, such that I can open
I am (quite) an experienced programmer but totally new to Ruby and Ruby on
I am new to ROR, i follow this tutorial to learn ROR,however, it show
I am new to RoR and I am experiencing the 500 server error for
Absolute RoR newbie here, I'm trying to render out multiple leagues in a loop,
I'm new to RoR and started making a project recently. The project has public/stylesheets

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.