python 2.7 - 'module' csv has no attribute next -
i using csv iterator go through csv file, contains data associated time. sure csv file correct. using jupyter, ipython notebook in python 3.x
when try iterate on first row using .next() method, have attributeerror: 'module' object has no attribute 'next'.
my code divided in 2 parts, 1 part containing function , imports, 1 part calling them. function have problem is:
def get_durations(csvfile): try: csvfile = iter(csvfile) except typeerror, te: print csvfile, 'is not iterable' print "data is", repr(csvfile) first_time = csvfile.next()[5] first_time = (first_time.replace(" ", "")); row in csvfile: last_time = row[5] last_time = (last_time.replace(" ", "")) first_time = datetime.datetime.strptime(first_time, "%h:%m:%s") last_time = datetime.datetime.strptime(last_time, "%h:%m:%s") return first_time.replace(second = 0), last_time.replace(second = 0)
i make call function here:
for el_mousefile in mousefiles: os.chdir(el_mousefile) print "data is", repr(csvfile) csvfile = csv.reader(open("mouse.csv", "ru"), delimiter=';', quoting=csv.quote_none) print "data is", repr(csvfile) try: csvfile = iter(csvfile) except typeerror, te: print csvfile, 'is not iterable' first_time, last_time = get_durations(csv)
i output when trying run program:
data <_csv.reader object @ 0x000000000a388d08> data <_csv.reader object @ 0x000000000a388948> module 'csv' 'c:\users\**\appdata\local\continuum\anaconda\lib\csv.pyc' not iterable data module 'csv' 'c:\users\**\appdata\local\continuum\anaconda\lib\csv.pyc' 96------>first_time = csvfile.next()[5] 97 first_time = (first_time.replace(" ", "")); 98 row in csvfile: attributeerror: 'module' object has no attribute 'next'
i don't understand how can csv iterable in second part, when being passed function, not iterable anymore responsible error.
first_time, last_time = get_durations(csv)
you passing in csv module, not file.
Comments
Post a Comment