468,284 Members | 1,573 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,284 developers. It's quick & easy.

how to convert UNICODE to integer in Python?

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
2 9138
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

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.

Similar topics

23 posts views Thread by Hallvard B Furuseth | last post: by
4 posts views Thread by Uwe Mayer | last post: by
7 posts views Thread by Philipp H. Mohr | last post: by
5 posts views Thread by Allerdyce.John | last post: by
3 posts views Thread by GM | last post: by
reply views Thread by willie | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.