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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:29+00:00 2026-05-26T12:09:29+00:00

So I am trying to put the result of a query in a string.

  • 0

So I am trying to put the result of a query in a string. Let’s say row by row (I don’t need all the fields by the way), but that’s not the point. I am using python against a sqlite db.

the problem is that when some of the fields are null, python will write None instead of “” or some blank neutral thing.

example:

   t = "%s %s %s %s" % (field[1],field[2],field[3],field[4])

If field[3] is null for instance, t will be something like

"string1 string2 None string4"

instead of

"string1 string2 string4"

yes I would need to remove also the double space in case. I cannot just replace “None” with “” because some string might contain itself “None” since it is a common word. Of course I don’t have only 4 field, they are a lot, and I am not trying to import every field of the row, only specific ones. I need a fast and easy way to fix this behavior. I cannot manually check if each field is None, that’s insane. I cannot use

str.strip(field[i])

because when the field is None I get an error.

what could be a good approach?

  • 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-26T12:09:30+00:00Added an answer on May 26, 2026 at 12:09 pm

    There is the str.replace option if “None ” is unique to NULL fields:

    >>> "string1 string2 None string4".replace('None ', '')
    'string1 string2 string4'
    

    Or you can pre-filter the strings:

    >>> fields = ['string0', 'string1', 'string2', None, 'string4']
    >>> fields_out = filter(lambda f: f is not None, fields[1:])
    >>> template = ' '.join('%s' for field in fields_out)
    >>> template % tuple(fields_out)
    'string1 string2 string4'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, let me say that I know that http://sphinxsearch.com/docs/current.html#conf-sql-attr-string says strings can only be
I'm trying to query an MySql table, put all results into a combobox. So
Hi all i am trying to achieve below query to return result from two
I am trying to figure out how to put a mysql query result into
I'm trying to put together a query that will retrieve the statistics of a
I am trying to put together a query that gives me a report of
I trying to put together an Android app that will take a picture and
I am trying to put some custom text on the popup that asks for
I'm building a simple app and trying to test DB result output. But unfortunately
I'm trying to run a Linq query on a datatable to produce a result,

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.