[Tutor] unpacking PyTime

Etrade Griffiths etrade.griffiths at dsl.pipex.com
Wed May 17 21:43:05 CEST 2006


Bob

I was looking at

http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/pywin32/PyTime.html

To my untrained eye it looks like there are a number of functions for 
PyTime objects (eg __int__, __hash__ etc).  However, I tried int(curr_date) 
and it seems to work OK - thanks!

At 19:11 17/05/2006, Bob Gailer wrote:
>Etrade Griffiths wrote:
>>Hi
>>
>>I am using the Win32com library to pick up data from an EXCEL spreadsheet 
>>but am having trouble with dates.  I want to convert a date read from the 
>>XL sheet into a float using this snippet
>>
>>from win32com.client import dispatch
>>import time
>>
>>xlFile="test.xls"
>>xlApp=Dispatch("Excel.Application")
>>xlApp.Workbooks.Open(xlFile)
>>xlSht=xlApp.Worksheets("data")
>>
>># OK so far but the problem comes now ...
>>
>>curr_date=xlSht.Cells(1,3).Value         # returns PyTime
>>
>>Not how to get the date (as either yy,mm,dd or a single number aka 
>>XL).  The ASPN ActivePython site suggests using
>>
>It appears that the ActivePython docs may be wrong, as the only method I 
>see for a PyTime object is Format. Looking up Format leads to 
>curr_date.Format("%y,%m,%d") to get yy,mm,dd.
>
>Or you can, as the ActivePython docs suggest, use int(curr_date) to get an 
>integer value which you can then float.
>
>--
>Bob Gailer
>510-978-4454




More information about the Tutor mailing list