I trying to create csv file from txt file with only one row.
Txt file looks like this:
My code is:
row = []
with open('vehicles.txt', 'r', encoding='utf-8') as r:
r = len(r.readlines())
with open('vehicles.txt', 'r', encoding='utf-8') as f:
for i in range(r):
data = {
'vehicle': f.readline().strip()
}
row.append(data)
csv_title = ['vehicle']
with open('vehicle.csv', 'w', encoding='utf-8', newline='') as f:
writer = csv.DictWriter(f, fieldnames=csv_title)
writer.writeheader()
writer.writerows(row)
But csv file creates with empty rows
How can I remove these empty lines? When I print this in the terminal, it goes without empty lines
edit:
Adding a newline="" also doesn't help. The csv files still goes with empty rows


newline=""csv.DictReaderinstead. Plus edit your question to show where you insertednewline=""because it's not clear