[Tutor] Formating from hhmms to hh:mm:ss
greg whittier
greg at thewhittiers.com
Sun Sep 7 19:17:41 CEST 2008
Is this an actual cut and paste of your code? The problem seems to be that
you're getting a time.struct_time object instead of a datetime object. See
below
On Sun, Sep 7, 2008 at 12:52 PM, Wayne Watson
<sierra_mtnview at sbcglobal.net>wrote:
> Yes, that's correct., but that reference isn't doing it for me presently.
> Here's a piece of code that might help explain what I'm trying to do:
>
> # program to test str... functions
> import datetime
>
> Are you sure you didn't do "from datetime import datetime"?
>
> ...
> # format conversion of date+time
> dt1 = datetime.strptime("20080421_101145", "%Y%m%d_%H%M%S")
>
> I don't see how this works as written because the datetime module doesn't
have a strptime function.
>
> print "dt1: ",dt1
> other = dt1.strftime("%Y%m%d_%H%M%S") <-- fails, line 11
> print other.replace(" ", "")
>
> Results:
> dt1: (2008, 4, 21, 10, 11, 45, 0, 112, -1)
>
>
> Traceback (most recent call last):
> File
> "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/BumpSeconds",
> line 11, in ?
> other = dt1.strftime("%Y%m%d_%H%M%S")
> AttributeError: 'time.struct_time' object has no attribute 'strftime'
>
>
This is telling you that dt1 is a time.struct_time but I don't see how from
the code you've shown here.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080907/be4d30ad/attachment.htm>
More information about the Tutor
mailing list