1 Replies - 572 Views - Last Post: 09 July 2020 - 01:51 PM Rate Topic: -----

#1 pranabpal   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 02-April 19

csv file reading

Posted 09 July 2020 - 01:28 PM

I need to invoke the function read_csv_fieldnames as defined but getting an error. What need to be rewritten. Please let me know

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")




error:

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


Is This A Good Question/Topic? 1
  • +

Replies To: csv file reading

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15965
  • View blog
  • Posts: 63,898
  • Joined: 12-June 08

Re: csv file reading

Posted 09 July 2020 - 01:51 PM

Is the problem you have a tick mark, comma, and tick mark instead of one character?

','
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1