I want to import a CSV file that contains information and it has random empty lines that I want to ignore and just skip over for example I have a .txt file that contains this information set up just like this:
Audi 90;200;Germany;22/10/19;150;
Bmw e46;350;Germany;22/10/19;100;
Mazda mx5;183;Japan;20/09/19;97;
Ford mustang;350;USA;21/04/19;278;
Lada;99999;Russia;20/11/19;99999;
And I want my code to output it like this:
Audi 90;200;Germany;22/10/19;150;
Bmw e46;350;Germany;22/10/19;100;
Mazda mx5;183;Japan;20/09/19;97;
Ford mustang;350;USA;21/04/19;278;
Lada;99999;Russia;20/11/19;99999;
My code for opening and setting up the table looks like this :
import csv
from tabulate import tabulate as tb
def file_opening():
file = input("Enter .txt file name:")
open(file + '.txt', 'r')
fields = list(csv.reader(open(file + '.txt', 'r'), delimiter=';'))
print(tb(fields, headers=['Car name', 'How many on road', 'Country of origin', 'Last update data', 'How many left', ''])