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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:29:48+00:00 2026-05-28T13:29:48+00:00

Here are three pieces of similar code, the first two run fine, the last

  • 0

Here are three pieces of similar code, the first two run fine, the last one fails —

    # 1
    print '%d) "%s" ' % (new_item_count, item[u'Title'].encode('utf-8')),
    print '%s' % item[u'CurrencyID'],
    print '%s !' % item[u'Value']

    # 2
    print '%d) "%s" %s%s !!' % (new_item_count,
            item[u'Title'].encode('utf-8'),
            item[u'CurrencyID'].encode('utf-8'),
            item[u'Value'])

    # 3
    print '%d) "%s" %s%s !!!' % (new_item_count,
            item[u'Title'].encode('utf-8'),
            item[u'CurrencyID'],
            item[u'Value'])

Output (note the differentiating exclamation marks at the end) —

37) "HP Pavilion Laptop / Intel® Core™ i3 Processor"  USD 510.0 !
37) "HP Pavilion Laptop / Intel® Core™ i3 Processor" USD510.0 !!
'ascii' codec can't decode byte 0xc2 in position 29: ordinal not in range(128)

This is under Python 2.6.5 (Ubuntu 10.04 package, same behaviour in both 32bit and 64bit) —

$ python -V
Python 2.6.5
$ uname -a
Linux <> 2.6.39.1-x86_64-<> #1 SMP Tue Jun 21 10:04:20 EDT 2011 x86_64 GNU/Linux

The only explanation I can think of is that it’s a Python bug.

Or is it?

  • 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-28T13:29:49+00:00Added an answer on May 28, 2026 at 1:29 pm

    You might even have triggered some incosisntency in there, but as it is, your code – in all of the examples. is somewhat messy.

    You should not mix unicode and non-unicode strings like that

    Please, tale a look at http://www.joelonsoftware.com/articles/Unicode.html – the article gives one a nice understanding of what unicode and different encodings actually are, and make it a lot easier to code anything afterwards.

    As for your specific snippet, if all your data in the “item” dictionary is appropriately in unicode, as it seens, just do the string interpolation in unicode, and just encode the final resulting string to the intended output format:

    message = u'%d) "%s" %s%s !!!' % (new_item_count,
                item[u'Title'],
                item[u'CurrencyID'],
                item[u'Value']))
    print message.encode("utf-8")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

okey so here is my structure. one.php two.php three.php one.php includes both two.php and
The following three pieces of code achieves exactly the same effect. Yet, when compiled
I'm having some problems with a C++ piece of code similar to the one
I am having three arraylist,Here I have to concatenate 2 arraylist and display it
This is a continuation of this question from yesterday . Here are my three
Here are the constraints I have three buckets (water) capacities 10 litre, 2 liters
Here's my scenario: I need to make three or four calls to different WCF
I have three tables: Employee(EmployeeID,Fname,Lname...) ProjectHeader(ProjectID,LeadID,Status....) ProjectDetails(ProjectDetailsID,ProjectID....) Here's my current code: $get_projects = SELECT
Here's a tricky iPhone problem I've been working on. I have three UIScrollViews on
Rails noob here. I have a rails application with (in this example) three tables.

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.