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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:30:36+00:00 2026-05-26T02:30:36+00:00

I am processing the data reading from test.xls file like so: from sys import

  • 0

I am processing the data reading from test.xls file like so:

from sys import exe_info
    try:
        book = xlrd.open_workbook('test.xls')
        sh = book.sheet_by_index(0)
        for row in range( 1, sh.nrows ):
            for index, value in enumerate(sh.row_values(row)):
                process_value(value)
    except:
        print exc_info()[1]

If an exception is raised while processing the process_value(value) means there is some thing wrong in that particular row of .xls file.but when i am printing the exc_info()[1] I am able to get on the exception description like

'ascii' codec can't encode characters in position 7-10: ordinal not in range(128)

but if I print the exc_info() function it gives following output

(<type 'exceptions.UnicodeEncodeError'>, UnicodeEncodeError('ascii', u'bokor b\xe3\u0192\xe2\xa9la', 7, 11, 'ordinal not in
range(128)'), <traceback object at 0x01067080>)

So if I want to show exception to user then user is intrested in particular line of that.xls file which causing error .So in output of exc_info() I can see the word

u'bokor b\xe3\u0192\xe2\xa9la'

This is the word from XLS file. If we can’t show for which line error is raise if I at lease show that above word it will help to find that word and remove that word.
I am not able to get that particular word from exc_info() or is their is any better way to handle this situation?

  • 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-26T02:30:37+00:00Added an answer on May 26, 2026 at 2:30 am

    xlrd returns the contents of all text cells as unicode objects. You don’t need to know “the correct encoding” — it’s NOT encoded.

    I suggest that you do something like this:

    for row in xrange(1, sh.nrows):
        for index, value in enumerate(sh.row_values(row)):
            try:
                process_value(value)
            except:
                print >> sys.stderr, row, index, repr(value)
                raise
    

    That enables you to display all the relevant data, then re-raising the exception so that you get the formatted error message and traceback done for you.

    It would probably help us considerably to help you if you were to show us the code for your process_value function — are you attempting unicode_object.encode('ascii') explicitly or implicitly?

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

Sidebar

Related Questions

I'm having a problem reading and processing data from my server. I've spent hours
I have a pseudo-realtime data processing application where I would like to use LazyInit<double>
I want to scrape text data from a windows application to do additional processing
Here's an example of opening and reading data from a TCP socket. Is there
I need to read a large (2000x2000) matrix of binary data from a file
I'm reading raw data from a mic and feeding into FFT. Two of the
I am trying to load a file using the SQL Server Import Data function
C# code is reading data from database through dynamic queries. Select ID, TransDate from
I need ideas for structuring and processing data with revisions. For example, I have
In data processing, I frequently need to create a lookup data structure to map

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.