Entering edit mode
8.1 years ago
sven.lemoinebauer
▴
10
Hey everybody, probably stupid question, but I do not understand what is wrong there, I guess I just do not know how to properly open a file in a function. Having my csv file in the folder, I want to make a list out of the it:
def make_OTU_list(csvfile):
with open(csvfile, "rb") as list_input:
csv = csv.reader(list_input)
list_OTU = list(csv)[0]
return list_OTU
make_OTU_list("OTU95_dominating.csv")
and I come back with that:
Traceback (most recent call last):
File "labbook.py", line 35, in <module>
make_OTU_list("OTU95_dominating.csv")
File "labbook.py", line 31, in make_OTU_list
csv = csv.reader(list_input)
UnboundLocalError: local variable 'csv' referenced before assignment
Can somebody solve my problem? Thanks a lot!