When looping through the contents of a CSV file I am trying to create a start time and an end time;
I know the forms submitted based on the row['form']
and I log the time of submitting for those forms, I am trying to create a start
and end
time so I can later get an average time for the completion of their forms.
for row in rows:
branch = Branch(row['user_id'], row['form'], row['time'])
if branch.id == row['user_id']:
if branch.form == 'signup':
time = {i: {'start': branch.time}}
print(time)
elif branch.form == 'submit':
time = {i: {'end': branch.time}}
print(time)
print(time) # line 27
The problem with the code snippet above is that for the print()
inside of the conditional statements it works just fine; I get the start time as well as the end time.
But when I try to print it outside of the conditional statement it does not work:
Traceback (most recent call last):
File "index.py", line 27, in <module>
print(time)
NameError: name 'time' is not defined
Now, if I print
time
outside of the for
loop then it gives me the last value; I cannot get any of the previous values.