Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > TypeError: unsupported type for timedelta days component: unicode

Reply
Thread Tools

TypeError: unsupported type for timedelta days component: unicode

 
 
kath
Guest
Posts: n/a
 
      10-06-2006
Hi,

the following shows the contents of "datebook.xls"

Date
8/9/2006
8/9/2006
8/9/2006
8/9/2006
8/9/2006

# read_date.py
import xlrd

book = xlrd.open_workbook("datebook.xls")
sh = book.sheet_by_index(0)
ex_qdate=sh.cell_value(rowx=1,colx=0)
pyd=datetime.date(1900,1,1)+datetime.timedelta(day s=sh.cell_value(rowx=1,colx=0))
print pyd

for c in range(sh.ncols):
for r in range(sh.nrows):
print sh.cell_value(rowx=r,colx=c)
print
datetime.date(1900,1,1)+datetime.timedelta(days=sh .cell_value(rowx=r,colx=c))

---- Output ----
>>>

2006-08-11
Date
Traceback (most recent call last):
File "D:/Python23/Testing area/Python and Excel/read_date.py", line
12, in ?
print
datetime.date(1900,1,1)+datetime.timedelta(days=sh .cell_value(rowx=r,colx=c))
TypeError: unsupported type for timedelta days component: unicode
>>>


The first print statement gives me desired output. Whats wrong with
second print statement?
When I give the discriptor or index explicitly its giving the correct
answer.
Why not in the loop?

Am I wrong some where?


Please help me.
Thank you,
Sudhir.

 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      10-06-2006
kath wrote:
> Hi,
>
> the following shows the contents of "datebook.xls"
>
> Date
> 8/9/2006
> 8/9/2006
> 8/9/2006
> 8/9/2006
> 8/9/2006
>
> # read_date.py
> import xlrd
>
> book = xlrd.open_workbook("datebook.xls")
> sh = book.sheet_by_index(0)
> ex_qdate=sh.cell_value(rowx=1,colx=0)
> pyd=datetime.date(1900,1,1)+datetime.timedelta(day s=sh.cell_value(rowx=1,colx=0))


############################
Go back and read *ALL* the responses to your previous question. The
above is *INCORRECT*. As you can see, for input of 8/9/2006 (M/D/YYYY
format), it produces 2006-08-11.
*Please* read the sections on Excel dates in the xlrd documentation.
############################

> print pyd
>
> for c in range(sh.ncols):
> for r in range(sh.nrows):
> print sh.cell_value(rowx=r,colx=c)


Problem 1: you are including the heading.
Add this in here:
print "row %d, col %d, cell_type %d" % (r, c,
sh.cell_type(r, c))
and that might give you a clue.

> print
> datetime.date(1900,1,1)+datetime.timedelta(days=sh .cell_value(rowx=r,colx=c))


Maybe Problem 2: your posting seems to be missing indentation on this
line.

>
> ---- Output ----
> >>>

> 2006-08-11
> Date
> Traceback (most recent call last):
> File "D:/Python23/Testing area/Python and Excel/read_date.py", line


How do you manage to get both "D:" and "/" in a path? Which version of
which OS are you running?

Why are you using Python 2.3?

Why are you keeping your own files in a subdirectory of your Python
installation?

> 12, in ?
> print
> datetime.date(1900,1,1)+datetime.timedelta(days=sh .cell_value(rowx=r,colx=c))
> TypeError: unsupported type for timedelta days component: unicode
> >>>

>
> The first print statement gives me desired output. Whats wrong with
> second print statement?
> When I give the discriptor or index explicitly its giving the correct
> answer.
> Why not in the loop?


As explained above.

>
> Am I wrong some where?


I think that's not an reasonable conclusion

HTH,
John

 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      10-06-2006
John Machin wrote:

> Why are you keeping your own files in a subdirectory of your Python
> installation?


IDLE defaults to the installation directory, so that's an easy thing
to do. and as long as you put it in a subdirectory, it's not much of a
problem either. (at least not until you want to uninstall Python...)

</F>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
time + timedelta josh@yucs.org Python 0 02-07-2005 04:24 PM
why no time() + timedelta() ? josh Python 0 01-20-2005 03:46 PM
Creating a timedelta counter... Wil Schultz Python 2 07-23-2004 01:47 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments