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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:18:07+00:00 2026-05-28T19:18:07+00:00

Ok.. This might be the duplicate.. but I dont think I even know the

  • 0

Ok.. This might be the duplicate.. but I dont think I even know the right problem.
I am guessing I have a string in unicode.. (basically i am reading from mongo db.. and mongodb stores everything in that form???? Honestly I am not sure.. but this is what I get..

{ u'preview': u'Hello World!!'}

so there is this u’ in front of all the fields..
I am basically trying to extract these out!! and then append them in one giant string.
so lets say I do something like:

 string =  ''
 resolve = foo['first_resolved_at']
 string += resolve

So it throws an error

TypeError: coercing to Unicode: need string or buffer, NoneType found

What am I doing wrong?
I guess I have to convert it to a string.. but how???
Thanks

  • 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-28T19:18:08+00:00Added an answer on May 28, 2026 at 7:18 pm

    Even though the answer was accepted, I thought I would include for reference an example of how you should be using join() instead of adding strings together. This also shows you that its avoiding None values:

    d = {u'a': u'a', u'c': None, u'b': u'b', u'e': None, u'd': None, u'g': u'g', u'f': u'f', u'i': u'i', u'h': u'h', u'k': u'k', u'j': u'j', u'm': None, u'l': u'l', u'o': u'o', u'n': None, u'p': u'p'}
    
    resolve = ''.join((value for value in d.itervalues() if value is not None))
    print resolve
    # u'abgfihkjlop'
    

    And if what you wanted to do was only loop over a predetermined set of keys:

    keys = ('c', 'g', 'f', 'm')
    ''.join([v for v in (d[k] for k in keys) if v is not None])
    

    Here is a test showing the difference between this approach, appending to a list, and adding strings together:

    from time import time
    
    d = {}
    for i in xrange(1000):
        v = u'v%d' % i
        d[v] = v
    
    def test1():
        return ''.join(v for v in d.itervalues() if v is not None)
    
    def test2():
        result = []
        for v in d.itervalues():
            if v is not None:
                result.append(v)
        return ''.join(result)
    
    def test3():
        result = ''
        for v in d.itervalues():
            if v is not None:
                result += v
        return result
    
    def timeit(fn):
        start = time()
        r = fn()
        end = time() - start
        print "Sec:", end, "msec:", end*1000
    
    
    >>> timeit(test1)
    Sec: 0.000195980072021 msec: 0.195980072021
    >>> timeit(test2)
    Sec: 0.000204086303711 msec: 0.204086303711
    >>> timeit(test3)
    Sec: 0.000397920608521 msec: 0.397920608521
    

    You can see that when your loops get bigger it really makes a difference.

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

Sidebar

Related Questions

This might sound like a duplicate, but I have searched through the forum questions
Possible Duplicate: How is std::iostream buffered? This might sound ridiculous, but how can I
This is an extension of this question and probably might even be a duplicate
this might be fairly simple but I cant find my way around... I have
This might seems silly question but for me it is annoying. I have installed
this might look silly to you but I am stuck here . I have
Greets. I realize this might be seen as a duplicate question as this but
Ok, you might say that this is a duplicate post but it is different.
Disclaimer: This might be a duplicate of datetime vs. timestamp? , but I feel
I know that this might be a duplicate of: Return a "NULL" object if

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.