[Tutor] deltatime difficulty

Don Jennings dfjennings at gmail.com
Fri Sep 19 02:54:04 CEST 2008


On 9/18/08, Wayne Watson <sierra_mtnview at sbcglobal.net> wrote:
> What's the problem here. It seems right to me. line 9 is diff =...
>>
>> import time
>> from datetime import datetime
>> def adjust_ftime(afilename, sec):
>>     # Vyyyymmdd_hhmmss+tag, seconds in, new yyyymmdd_hhmmss out
>>     ts = afilename[1:-7]      # use time stamp portion
>>     format = '%Y%m%d_%H%M%S'
>>     d = datetime(*(time.strptime(ts, format)[0:6]))
>>     print "sec: ", sec, type(d)
>>     diff = datetime.timedelta(seconds = sec)
>>     print type(diff)
>>     d = d + diff
>>     return d.strftime(format)
>>
>> adjust_ftime('v20080120_000020.xx.dat',  33)
>
>
> Results:
> sec:  33 <type 'datetime.datetime'>
> Traceback (most recent call last):
>   File
> "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py",
> line 14, in ?
>     adjust_ftime('v20080120_000020.xx.dat', 33)
>   File
> "C:/Sandia_Meteors/Improved_Sentinel/Sentinel_Playground/Utility_Dev/junk.py",
> line 9, in adjust_ftime
>     diff = datetime.timedelta(seconds = sec)
> AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'
>


Wayne,

You only imported datetime from the datetime module. If you want to
use timedelta, you'll need to import that, too. Then your line 9
becomes:

diff = timedelta(seconds = sec)

Take care,
Don


More information about the Tutor mailing list