python one more stupid debug -


sorry, bit of pain damaged code, cannot understand wrong. removed if statement appears timedelta not recognized anymore , breaks code. pretty sure havent removed of reference though. scratching head cannot find problem..

would know went wrong?

import random import datetime import csv itertools import groupby    def generator():      i=0     while 1:         yield random.randint(-1, 1), datetime.datetime.now()         i=i+1   def keyfunc(timestamp,interval):     xt = datetime.datetime(2013, 4,4)     dt=timestamp     delta_second =(dt - xt).seconds     normalize_second = (delta_second / (interval*60)) * (interval*60)     newtime = xt + timedelta(seconds=normalize_second)     return newtime   mynumber = 100 random_number, current_time in generator():     mynumber += random_number     reftime5min = keyfunc(current_time,5)   print mynumber,",", current_time, reftime5min 

the error is:

 traceback (most recent call last):   file "", line 35, in    file "", line 28, in keyfunc nameerror: global name 'timedelta' not defined 

change timedelta datetime.timedelta. you're not importing timedelta class directly, need use qualified name.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -