Off topic:opening a file wih a function in python
2
1
Entering edit mode
8.1 years ago

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!

python csv • 2.5k views
ADD COMMENT
This thread is not open. No new answers may be added
Traffic: 1954 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6