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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:08:40+00:00 2026-05-23T09:08:40+00:00

Using python to pick it some pieces so definitely a noob ? here but

  • 0

Using python to pick it some pieces so definitely a noob ? here but didn’t seeing a satisfactory answer.

I have a json utf-8 file with some pieces that have grave’s, accute’s etc…. I’m using codecs and have (for example):

str=codecs.open('../../publish_scripts/locations.json', 'r','utf-8')
locations=json.load(str)

for location in locations:
    print location['name']

For print’ing, does anything special need to be done? It’s giving me the following
ascii’ codec can’t encode character u’\xe9′ in position 5

It looks like the correct utf-8 value for e-accute. I suspect I’m doing something wrong with print’ing. Would the iteration cause it to lose it’s utf-8’ness?

PHP and Ruby versions handle the utf-8 piece fine; is there some looseness in those languages that python won’t do?

thx

  • 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-23T09:08:41+00:00Added an answer on May 23, 2026 at 9:08 am

    codec.open() will decode the contents of the file using the codec you supplied (utf-8). You then have a python unicode object (which behaves similarly to a string object).

    Printing a unicode object will cause an implict (behind-the-scenes) encode using the default codec, which is usually ascii. If ascii cannot encode all of the characters present it will fail.

    To print it, you should first encode it, thus:

    for location in locations:
        print location['name'].encode('utf8')
    

    EDIT:

    For your info, json.load() actually takes a file-like object (which is what codecs.open() returns). What you have at that point is neither a string nor a unicode object, but an iterable wrapper around the file.

    By default json.load() expects the file to be utf8 encoded so your code snippet can be simplified:

    locations = json.load(open('../../publish_scripts/locations.json'))
    for location in locations:
        print location['name'].encode('utf8')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using urllib2 (and maybe urllib) on windows python seems to magically pick up
When using Python's super() to do method chaining, you have to explicitly specify your
I want to start using Python for small projects but the fact that a
I am using python 2.6 on XP. I have just installed py2exe, and I
How can I pick tags from an article or a user's post using Python?
I have a small project I am doing in Python using web.py. It's a
I'm trying to run an Icecast stream using a simple Python script to pick
Im using python markdown for my django project, when i have the value #/usr/bin/env
I am using BeautifulSoup in Python and am having trouble replacing some tags. I
I started using Python in 2001. I loved the simplicity of the language, but

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.