sniff
import csv
class Data(object):
def __init__(self, csv_file):
self.raw_data = []
self.read(csv_file)
def read(self, csv_file):
with open(csv_file, newline='') as csvfile:
dialect = csv.Sniffer().sniff(csvfile.read())
csvfile.seek(0)
f = csv.reader(csvfile, dialect)
for row in f:
self.raw_data.append(row)
print(csvfile.name)
print(self.raw_data)
for f in ['tab_separate.tsv','comma_separate.csv','comma_separate2.csv']:
mycsv = Data(f)
tab_separate.tsv
[['afsfaf@faf.com', '$161,321', 'True', '1'], ['asafasf@fafa.net', '$95.00', 'False', '3'], ['adaafa3@aca.com', '$952025', 'False', '3']]
comma_separate.csv
[['afsfaf@faf.com,', '$161,321,', 'True,', '1'], ['asafasf@fafa.net,', '$95.00,', 'False,', '3'], ['adaafa3@aca.com,', '$952025,', 'False,', '3']]
comma_separate2.csv
[['afsfaf@faf.com', '$161,321', 'True', '1'], ['asafasf@fafa.ne', '$95.00', 'False', '3'], ['adaafa3@aca.com', '$952025', 'False', '3']]
afsfaf@faf.com, $161,321, True, 1
asafasf@fafa.net, $95.00, False, 3
adaafa3@aca.com, $952025, False, 3
afsfaf@faf.com $161,321 True 1
asafasf@fafa.net $95.00 False 3
adaafa3@aca.com $952025 False 3
afsfaf@faf.com;$161,321;True;1
asafasf@fafa.ne;$95.00;False;3
adaafa3@aca.com;$952025;False;3