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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:59:05+00:00 2026-05-22T00:59:05+00:00

I have a function which connects to a url by httplib using lxml .

  • 0

I have a function which connects to a url by httplib using lxml. It checks by xpathfor a certain pattern and if the check is positive it returns a string. But if the check was negative it returns nothing.

Now the situation is, that my function returns None. I call the function, check if its return value is not None and continue in the code.

An example:

def foobar(arg):
    # connect to page by httplib
    # check for arg in a certain pattern by lxml
    if check:
        return result
    else:
        return None

result = foobar(arg)
if result:
    # do stuff
else:
    # do other stuff

Recently I read, that this is a no go. How do I avoid such situations?

  • 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-22T00:59:05+00:00Added an answer on May 22, 2026 at 12:59 am

    There is nothing wrong with returning None.

    In most cases, you don’t need to explicitly return None. Python will do it for you. This is an altered version of your foobar which behaves identically without explicitly returning None:

    def foobar(arg):
      if check:
        return result
    # If not check, then None will be returned
    

    Still, even if Python implicitly returns None, there is a value in being explicit; Your code becomes easier to read and understand. This is a constant trade-off for which there is no general answer.

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

Sidebar

Related Questions

I have a function that connects to the database and returns a number and
I have a function: def create(sender, **kw): [...] Which should be called when the
I would like to have my users specify custom URL paths such that those
I have a script that fetches several web pages and parses the info. (An
as the title specifies, my hosting provider does not have support for json_decode, so
I'm trying to build an array structured like [ [num, [num, num num]], [num,
At my campus, to get internet connection, I need to log on to a
I wanted to include the facebook login inside my application. This is the sample
Can somebody show me some examples to import a html-page and use the XPath
I've been searching the net for answers but I can't seem to find a

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.