I am trying to build a ticketing system in python, and the output should read the file column by column. However the program is misreading the columns. Any help would be greatly appreciated. Thank you
This is the expected output:
Name Age Sex
as 12 f
qw 13 m
Total Tickets: 2
And this is the current output:
Name Age Sex
as qw
12 13
f m
Total Tickets: 2
I am trying to create and write to a csv file and then read from it. However, as shown with the ouputs above, I am getting the opposite of the desired output
The code is as follows:
import sys, select, os, csv
from os import system
with open(input("\nInput file name with .csv extension: "), 'r', newline = '') as f:
fileDir = os.path.dirname(os.path.realpath('__file__'))
reader = csv.reader(f, delimiter = '\t')
header_row = next(reader)
# Can use the 2 lines below to check indices of headers
# name = [0], age = [1], sex = [2]
# for index, column_header in enumerate(header_row):
# print(index, column_header)
name_l = []
age_l = []
sex_l = []
total_tickets = 0
for row in reader:
name = str(row[0])
name_l.append(name)
age = str(row[1])
age_l.append(age)
sex = str(row[2])
sex_l.append(sex)
total_tickets += 1
print('\t'.join(header_row))
print('\t'.join(name_l))
print('\t'.join(age_l))
print('\t'.join(sex_l))
print("\nTotal Tickets: ", total_tickets)