From 68836e0d3ac99002c89ee8dcf5315d28a33bff5a Mon Sep 17 00:00:00 2001 From: Faizan Ansari <129893560+faizan35@users.noreply.github.com> Date: Tue, 19 Dec 2023 02:27:51 +0530 Subject: [PATCH] correctly showing CVS. --- pset6/pizza/pizza.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pset6/pizza/pizza.py b/pset6/pizza/pizza.py index 5bfd998..b38b4b7 100644 --- a/pset6/pizza/pizza.py +++ b/pset6/pizza/pizza.py @@ -7,13 +7,16 @@ def main(): check_csv(filename) try: - with open(filename,'r') as file: - reader=csv.reader(file) - table=[] - headers=list(next(reader)) + with open(filename, 'r') as file: + reader = csv.reader(file) + table = [] + headers = list(next(reader)) for row in reader: table.append([row[0], row[1], row[2]]) - print(tabulate(table, headers, tablefmt="grid")) + + # Move print statement outside the loop + print(tabulate(table, headers, tablefmt="grid")) + except FileNotFoundError: exit('File does not exist') except Exception as arg: @@ -24,8 +27,8 @@ def get_filename(arguments): if len(arguments) < 2: exit('Too few command-line arguments') else: - exit('Too mant command-line arguments') - return argv[1] + exit('Too many command-line arguments') + return arguments[1] def check_csv(filename): dot = filename.find('.') @@ -33,4 +36,4 @@ def check_csv(filename): exit('Not a CSV file') if __name__ == '__main__': - main() \ No newline at end of file + main()