filename_input = 'filein.txt'
filename_output = 'fileout.csv'
with open(filename_input, 'r') as f1:
    with open(filename_output, 'wb') as f2:
        dialect = csv.Sniffer().sniff(f1.read(1024), '\t')
f1.seek(0)
print(dialect.delimiter)
rows = csv.reader(f1, delimiter=dialect.delimiter)
writer = csv.writer(f2, delimiter=';')
writer.writerows(rows)
Find delimiter in txt to convert to csv using Python