472,371 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 13618
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)...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.