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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:26:59+00:00 2026-06-16T02:26:59+00:00

I am reading a list of strings that were imported into an excel xml

  • 0

I am reading a list of strings that were imported into an excel xml file from another software program. I am not sure what the encoding of the excel file is, but I am pretty sure its not windows-1252, because when I try to use that encoding, I wind up with a lot of errors.

The specific word that is causing me trouble right now is: “Zmysłowska, Magdalena” (notice the “l” is not a standard “l”, but rather, has a slash through it).

I have tried a few things, Ill mention three of them here:

(1)

page = unicode(page, "utf-8")
page = unicodedata.normalize("NFKD", page)
page = page.encode("utf-8", "ignore")

Output: Zmys\xc5\x82owska, Magdalena
Output after print statement: Zmysłowska, Magdalena

(2)

page = unicode(page, "utf-8")
page = unicodedata.normalize("NFKD", page)

Output: Zmys\u0142owska, Magdalena
Output after print statment: Zmysłowska, Magdalena

Note: this is great, but I need to encode it back to utf-8 before putting the string into my     db.  When I do that, by running page.encode("utf-8", "ignore"), I end up with Zmysłowska, Magdalena again.

(3)
Do nothing (no normalization, no decode, no encode). It seems like the string is already utf-8 when it comes in. However, when I do nothing, the string ends up with the following output again:

Output: Zmys\xc5\x82owska, Magdalena
Output after print statement: Zmysłowska, Magdalena

Is there a way for me to convert this string to utf-8?

  • 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-06-16T02:27:00+00:00Added an answer on June 16, 2026 at 2:27 am

    Your problem isn’t your encoding and decoding. Your code correctly takes a UTF-8 string, and converts it to an NFKD-normalized UTF-8 string. (You might want to use page.decode("utf-8") instead of unicode(page, "utf-8") just for future-proofing in case you ever go to Python 3, and to make the code a bit easier to read because the encode and decode are more obviously parallel, but you don’t have to; the two are equivalent.)

    Your actually problem is that you’re printing UTF-8 strings to some context that isn’t UTF-8. Most likely you’re printing to the cmd window, which is defaulting to Windows-1252. So, cmd tries to interpret the UTF-8 characters as Windows-1252, and gets garbage.

    There’s a pretty easy way to test this. Make Python decode the UTF-8 string as if it were Windows-1252 and see if the resulting Unicode string looks like what’re seeing.

    >>> print page.decode('windows-1252')
    Zmysłowska, Magdalena
    
    >>> print repr(page.decode('windows-1252'))
    u'Zmys\xc5\u201aowska, Magdalena'
    

    There are two ways around this:

    1. Print Unicode strings and let Python take care of it.
    2. Print strings converted to the appropriate encoding.

    For option 1:

    print page.decode("utf-8") # of unicode(page, "utf-8")
    

    For option 2, it’s going to be one of the following:

    print page.decode("utf-8").encode("windows-1252")
    print page.decode("utf-8").encode(sys.getdefaultencoding())
    

    Of course if you keep the intermediate Unicode string around, you don’t need all those decode calls:

    upage = page.decode("utf-8")
    upage = unicodedata.normalize("NFKD", upage)
    page = upage.encode("utf-8", "ignore")
    
    print upage
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a comma-delimited list of strings from a config file. I need to
Using Windows So I'm reading from a binary file a list of unsigned int
I have a program reading from a text file (currently 653 lines long) all
I am reading a list of strings, each of which relate to a file
I am reading from a list of strings like this: April 9, 2012 (2012-04-09)
I'm reading in a file and pulling in data that includes some strings and
I needed to merge strings that are inside List<string> together into oneliner. I came
I am reading XOR linked list (from Wikipedia).But I am having some problems in
I know from reading Microsoft documentation that the "primary" use of the IDisposable interface
I'm reading a table and it contains strings that describe timestamps. I just want

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.