how to convert UNICODE to integer in Python?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kath

    #1

    how to convert UNICODE to integer in Python?

    Hi,
    >>import xlrd
    >>book = xlrd.open_workb ook("testbook1. xls")
    >>sh = book.sheet_by_i ndex(0)
    >>sh.cell_value (rowx=1,colx=0)
    38938.0
    >>type(sh.cell_ value(rowx=1,co lx=0))
    <type 'unicode'>
    >>xlrd.xldate_a s_tuple( sh.cell_value( rowx = 1,colx= 0 ), 0 )
    Traceback (most recent call last):
    File "D:\Python23\Te sting area\Python and Excel\xlrdRead. py", line
    30, in ?
    temp=xlrd.xldat e_as_tuple(sh.c ell_value(rowx= r,colx=c),0)
    File "D:\PYTHON23\Li b\site-packages\xlrd\x ldate.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.

  • Fredrik Lundh

    #2
    Re: how to convert UNICODE to integer in Python?

    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>

    Comment

    • kath

      #3
      Re: how to convert UNICODE to integer in Python?


      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

      Comment

      Working...