1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| import csv import chardet
my_path = '.\\AuditTrail0.txt' with open(my_path, 'rb') as f: str1 = f.read() char_encoding= chardet.detect(str1) encoding_format = char_encoding["encoding"]
csv_file = '.\\AuditTrail0.csv'
with open(my_path,'r',encoding=encoding_format) as file: lines = file.readlines()
with open(csv_file,'w',newline='',encoding=encoding_format) as file: writer = csv.writer(file) for line in lines: row = line.strip().split('\t') writer.writerow(row)
|