Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import csv
import os
import sys
import tabulate
def main():
try:
file_name = sys.argv[1]
except IndexError:
print("Too few command-line arguments")
sys.exit(1)
if len(sys.argv) > 2:
print("Too many command-line arguments")
sys.exit(1)
if not os.path.isfile(file_name): # Or try opening and catch FileNotFoundError
print(f"File does not exist")
sys.exit(1)
if not file_name.endswith('.csv'):
print(f"Not a CSV file")
sys.exit(1)
grid = get_grid_from_csv(file_name)
print(grid)
def get_grid_from_csv(file_name: str) -> str:
headers = None
table = []
with open(file_name, 'r') as file_object:
reader = csv.DictReader(file_object)
for row in reader:
if headers is None:
headers = list(row.keys())
table.append(tuple(row[field] for field in row))
return tabulate.tabulate(table, headers, tablefmt="grid")
if __name__ == "__main__":
main()

View File

@@ -0,0 +1,6 @@
Regular Pizza,Small,Large
Cheese,$13.50,$18.95
1 topping,$14.75,$20.95
2 toppings,$15.95,$22.95
3 toppings,$16.95,$24.95
Special,$18.50,$26.95
1 Regular Pizza Small Large
2 Cheese $13.50 $18.95
3 1 topping $14.75 $20.95
4 2 toppings $15.95 $22.95
5 3 toppings $16.95 $24.95
6 Special $18.50 $26.95