By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,478 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

how to convert UNICODE to integer in Python?

P: n/a
Hi,
>>import xlrd
book = xlrd.open_workbook("testbook1.xls")
sh = book.sheet_by_index(0)
sh.cell_value(rowx=1,colx=0)
38938.0
>>type(sh.cell_value(rowx=1,colx=0))
<type 'unicode'>
>>xlrd.xldate_as_tuple( sh.cell_value( rowx = 1,colx= 0 ), 0 )
Traceback (most recent call last):
File "D:\Python23\Testing area\Python and Excel\xlrdRead.py", line
30, in ?
temp=xlrd.xldate_as_tuple(sh.cell_value(rowx=r,col x=c),0)
File "D:\PYTHON23\Lib\site-packages\xlrd\xldate.py", line 61, in
xldate_as_tuple
xldays = int(xldate)
ValueError: invalid literal for int(): Date

because xlrd.xldate_as_tuple() function expects first argument to be an
integer. How do I convert an unicode character to integer, so that I
could get the date using xlrd.xldate_as_tuple() function.

Thank you,
kath.

Oct 6 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
kath wrote:
xldays = int(xldate)
ValueError: invalid literal for int(): Date

because xlrd.xldate_as_tuple() function expects first argument to be an
integer. How do I convert an unicode character to integer, so that I
could get the date using xlrd.xldate_as_tuple() function.
the error doesn't say anything about Unicode characters, it says that
someone's passing the string "Date" to the int() function.
>>int("Date")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): Date

</F>

Oct 6 '06 #2

P: n/a

Fredrik Lundh wrote:
kath wrote:
xldays = int(xldate)
ValueError: invalid literal for int(): Date

because xlrd.xldate_as_tuple() function expects first argument to be an
integer. How do I convert an unicode character to integer, so that I
could get the date using xlrd.xldate_as_tuple() function.

the error doesn't say anything about Unicode characters, it says that
someone's passing the string "Date" to the int() function.
>>int("Date")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): Date

</F>

Hi,

Thanks for reminding me. I was wrong.

Regards,
kath

Oct 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.