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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:10:13+00:00 2026-05-24T08:10:13+00:00

My mind is probably feeling Friday afternoon and I cannot see a way to

  • 0

My mind is probably feeling Friday afternoon and I cannot see a way to pytonize the code below:

filepath = None
if 'HALLO' in os.environ:
    filepath = os.environ['HALLO']
elif os.path.isfile( os.path.join(os.environ['HOME'], 'host.hallo') ):
    filepath = os.path.join(os.environ['HOME'], 'host.hallo')
elif os.path.isfile('/etc/app/host.hallo'):
    filepath = '/etc/app/host.hallo'
if filepath:
    print 'HALLO found in "%s"' % filepath
    ## do something
else:
    print 'HALLO not found!'
    ## do something else

Any idea on how to do it? Thanks!

ps: the code above is just an example, it can have a syntax error since I have written it directly here.

  • 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-24T08:10:13+00:00Added an answer on May 24, 2026 at 8:10 am
    home_hallo = os.path.join(os.environ['HOME'], 'host.hallo')
    filepath = ( ('HALLO' in os.environ and os.environ['HALLO']) or
                 (os.path.isfile(home_hallo) and home_hallo) or
                 (os.path.isfile('/etc/app/host.hallo') and '/etc/app/host.hallo') )
    if filepath:
        print 'HALLO found in "%s"' % filepath
        ## do something
    else:
        print 'HALLO not found!'
        ## do something else
    

    See the documentation on Boolean operations if it isn’t clear why this works, here is the summary:

    The expression x and y first evaluates x; if x is false, its value is returned; otherwise, y is evaluated and the resulting value is returned.

    The expression x or y first evaluates x; if x is true, its value is returned; otherwise, y is evaluated and the resulting value is returned.

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

Sidebar

Related Questions

This is blowing my mind because it's probably an easy solution, but I can't
this is probably a useless problem but it stuck on my mind for few
This is probably very basic stuff, but please bear in mind I am completely
This is probably something mind-numbingly obvious, but I'm new to c# so be gentle...
The title is probably not very clear. I have the following example in mind:
I was wondering if the hive mind knew of an open source widget (probably
I know this is probably a simple question but my mind just isn't working
Ok, I'm probably just having an epic fail here, but my mind wants to
The question is probably worded in a very confusing way so here's a quick
Probably this is just the way Rails works, but I want to double-check because

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.