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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:26:11+00:00 2026-05-23T13:26:11+00:00

I recently had to implement a small check for any variables that might have

  • 0

I recently had to implement a small check for any variables that might have not been initialized (and their default value is None). I came up with this:

if None in (var1, var2, var3):
    error_out()

While, in my eyes, bordering on beautiful, I was wondering – is this a good way to do it? Is this the way to do it? Are there any cases in which this would produce some unexpected results?

  • 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-23T13:26:12+00:00Added an answer on May 23, 2026 at 1:26 pm

    First things first: your code is valid, readable, concise… so it might not be the way to do it (idioms evolves with time and new language features) but it certainly is one of the way to do it in a pythonic way.

    Secondly, just two observations:

    The standard way to generate errors in python is to raise Exceptions. You can of course wrap your exception-raising within a function, but since it’s quite unusual I was just wondering if you chose this design for some specific reason. Since you can write your own Exception class, even boilerplate code like logging an error message to file could go within the class itself rather than in the wrapping function.

    The way you wrote your test is such that you won’t be able to assign None as a value to your variables. This might be not a problem now, but might limit your flexibility in the future. An alternative way to check for initialisation could be to simply not declare an initial value for the variable in question and then do something along the lines of:

    try:
        self.variable_name
    except NameError:
        # here the code that runs if the variable hasn't been initialised
    finally:
        # [optional] here the code that should run in either case
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently had two telephone interviews where I've been asked about the differences
Recently I implemented an interface which had some 130 members that i should implement
Recently, I've had a request to implement logging for all of the Controller classes
I recently had a need to interpret a DEC 32-bit floating point representation. It
I recently had to work on a project where the previous developer modified the
We recently had a code review . One of my classes was used so
I recently had a problem during the deployment of a windows service. Four computers
I recently had a problem in my app where some of the subviews I
I recently had to take a quick look at Adobe InDesign server. In this
I recently had a discussion on another forum with another developer and the topic

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.