I have to invoke the function read_csv_fieldnames in the format shared below:
Getting an error.
############################################
import csv
def read_csv_fieldnames(filename, separator, quote):
with open(filename, mode ='r')as file:
print(separator)
print(quote)
# reading the CSV file
csvFile = csv.reader(file,delimiter = separator,quoting = quote)
# displaying the contents of the CSV file
for lines in csvFile:
print(lines)
return 1
read_csv_fieldnames("table1.csv","','","csv.QUOTE_NONE")
################################
Traceback (most recent call last):
File “read_csv_fieldnames.py”, line 14, in
read_csv_fieldnames(“table1.csv”,“‘,’”,“csv.QUOTE_NONE”)
File “read_csv_fieldnames.py”, line 8, in read_csv_fieldnames
csvFile = csv.reader(file,delimiter = separator,quoting = quote)
TypeError: “delimiter” must be a 1-character string
after i changed:
“,” --> ‘,’ read_csv_fieldnames("table1.csv",',',"csv.QUOTE_NONE")
getting this error:
Traceback (most recent call last):
File "read_csv_fieldnames.py", line 14, in <module>
read_csv_fieldnames("table1.csv",',',"csv.QUOTE_NONE")
File "read_csv_fieldnames.py", line 8, in read_csv_fieldnames
csvFile = csv.reader(file,delimiter = separator,quoting = quote)
TypeError: "quoting" must be an integer
in function you are passing string “csv.QUOTE_NONE” but in actual it is expecting integer in quoting = quote . so, please convert quote to str(quote ) and try it in case you need string.
basically, type of data passed is creating issue as quoting = quote [quote is an integer and you are trying to pass string csv.QUOTE_NONE as argument]