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

  • Home
  • SEARCH
  • 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 8414833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:16:07+00:00 2026-06-10T01:16:07+00:00

I’m accesing an Excel thru python to adjust some encoding of the cells. My

  • 0

I’m accesing an Excel thru python to adjust some encoding of the cells. My code so far:

from xlrd import *
from xlwt import *

wb = open_workbook('a.xls')

s = wb.sheets()[0]

for row in range(s.nrows):
e = s.cell(row,9).value
r = s.cell(row,11).value
print e,' ',r.decode('cp1251')

When running this code I get this error:

Traceback (most recent call last):
  File "C:\Users\pem\workspace\a\src\a.py", line 17, in <module>
    print e,' ',r.decode('cp1251')
  File "C:\Python27\lib\encodings\cp1251.py", line 15, in decode
    return codecs.charmap_decode(input,errors,decoding_table)
  File "C:\Python27\lib\encodings\cp1251.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character u'\xf6' in position 23: character maps to <undefined>

I know that e is english text and r is the russian translation in 1251 encoding.

  • 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-10T01:16:09+00:00Added an answer on June 10, 2026 at 1:16 am

    I assume you’re using Python 2. (Unicode handling is different in Python 3.)

    Use r.decode('cp1252') to decode r in your encoding into unicode. This will give you an object of type unicode.

    Note that if you try to print it, it will be first implicitly encoded, i.e. converted back to str with default encoding ansi. If your console supports unicode, you can print it by saying:

    print xyz.encode('utf-8')
    

    Note that Python’s str string consists of 8-bit bytes (characters), while unicode represents an actual string where one character can be any unicode character. (In Python 3, str was replaced by bytes and unicode renamed to str to make this more obvious.)

    .decode() on a str allows you to get a “meaningful” unicode string out of some bytes (that you read from somewhere) using an encoding you specify, while .decode() on an unicode object does the opposite: allows you to get the byte representation of a string using an encoding of your choice.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from

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.