I am creating a very rudimentary "Address Book" program in Python. I am grabbing contact data from a CSV file, the contents of which looks like the following example:
Name,Phone,Company,Email
Elon Musk,454-6723,SpaceX,emusk@spacex.com
Larry Page,853-0653,Google,lpage@gmail.com
Tim Cook,133-0419,Apple,tcook@apple.com
Steve Ballmer,456-7893,Developers!,sballmer@bluescreen.com
I am trying to format the output so that it looks cleaner and more readable, i.e. everything lined up in rows and columns, like this:
Name: Phone: Company: Email:
Elon Musk 454-6723 SpaceX emusk@spacex.com
My current code is as follows:
f = open("contactlist.csv")
csv_f = csv.reader(f)
for row in csv_f:
print(row)
Which naturally due to lack of formatting, produces this, which still looks very unclean.
['Name', 'Phone', 'Company', 'Email']
['Elon Musk', '454-6723', 'SpaceX', 'emusk@spacex.com']
['Larry Page', '853-0653', 'Google', 'lpage@gmail.com']
['Tim Cook', '133-0419', 'Apple', 'tcook@apple.com']
['Steve Ballmer', '456-7893', 'Developers!', 'sballmer@bluescreen.com']
Any tips on how to produce a cleaner output would be greatly appreciated, as I am beginner and I find all of this quite confusing. Many thanks in advance.