473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

TypeError: unsupported type for timedelta days component: unicode

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.

Oct 6 '06 #1
2 13955
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

Oct 6 '06 #2
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>

Oct 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Martin Koekenberg | last post by:
Hello, Ik get the following error when I install a new Python software package such as Zope or PIL. This is what I get whem I 'make' Zope : running build_ext Traceback (most recent call...
1
by: Florian Lindner | last post by:
Hello, I want to know if a certain duration is over. I try it like this with timedelta objects: d = datetime.timedelta(minutes = 2) t = time.gmtime() print (t + d < time.gmtime()) gives:
2
by: talam | last post by:
We had an old application developed using Visual Basic Language. We are trying to replace that application with .net 2005, C# Language. In the old application, we had a file attachment component....
1
by: Philipp | last post by:
Hello Pythonistas I'm new to Python, I hope you understand my question. I would like to pass a parameter "gap" to a function. gap should be used there to create a timedelta Object. from...
20
by: elderic | last post by:
Hi there, are there other ways than the ones below to check for <type 'function'> in a python script? (partly inspired by wrapping Tkinter :P) def f(): print "This is f(). Godspeed!" 1.:...
2
by: erikcw | last post by:
Hi, I'm parsing xml data with xml.sax and I need to perform some arithmetic on some of the xml attributes. The problem is they are all being "extracted" as unicode strings, so whenever I try to...
8
by: Gilbert Fine | last post by:
This is a very strange exception raised from somewhere in our program. I have no idea how this happen. And don't know how to reproduce. It just occurs from time to time. Can anyone give me some...
2
by: skip | last post by:
Running from Subversion, I see confusing (to me) behavior related to division of datetime.timedelta objects by integers: % python Python 2.6a0 (trunk:57277:57280M, Aug 28 2007, 17:44:49) on...
2
by: Jordan Harry | last post by:
I'm trying to write a simple program to calculate permutations. I created a file called "mod.py" and put the following in it: def factorial(n): a = n b = n while a>0 and b>1: n = (n)*(b-1)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.