Re: [Tutor] unpacking PyTime

2006-05-17 Thread Etrade Griffiths
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


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] unpacking PyTime

2006-05-17 Thread Bob Gailer
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

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] unpacking PyTime

2006-05-17 Thread Etrade Griffiths
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

x=curr_date.__float__()

but Python gives the error "AttributeError: __float__"

I also tried

x=float(curr_date)

but Python gives the error "TypeError: float() argument must be string or a 
number".  All suggestions gratefully received!  


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor