python - xlrd invalid literal for int() with base 10 -


i need parse cell contains data format 'tuesday, january 3, 2012 2:46pm'. code below gives error

invalid literal int() base 10: 'tuesday, january 3, 2012 2:46pm' 

may know right way parse string datetime?

book = xlrd.open_workbook(f) sh = book.sheet_by_index(0) rx in range(1, 10):  #sh.nrows     m = sh.row(rx)     print datetime(xlrd.xldate_as_tuple(m[0].value, book.datemode)) 

traceback

file "c:\anaconda\lib\site-packages\xlrd\xldate.py", line 67, in xldate_as_tuple     xldays = int(xldate) valueerror: invalid literal int() base 10: 'tuesday, january 3, 2012 2:46pm' 

first of all, not think m[0] has xldate value, looks coming string.

@sait's answer good. if not want use dateutil , can use datetime.datetime.strptime() function -

datetime.strptime('tuesday, january 3, 2012 2:46pm', '%a, %b %d, %y %h:%m%p') 

in case -

print datetime.strptime(m[0].value, '%a, %b %d, %y %h:%m%p') 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -