1
from tabulate import tabulate
import sys
import os



if len(sys.argv) < 2:
        sys.exit("Too few Command-line argument")
elif len(sys.argv) > 2 :
        sys.exit("Too many Command-line argument")
elif ".csv" not in sys.argv[1]:
        sys.exit("Not a csv file")
elif not os.path.exists(sys.argv[1]):
        sys.exit("File not found")

with open(sys.argv[1]) as file:
        table=[]
        for line in file:
            
                typ , small , large = line.split(",")
                list = [typ,small,large]
                table.append(list) 
            
        print(tabulate(table, headers = "firstrow" , tablefmt="grid") )  

what is wrong with this code, it works pretty fine for me, but still there is that :-

:( pizza.py renders prices from sicilian.csv expected "+-------------...", not "+-------------..." :( pizza.py renders prices from regular.csv expected "+-------------...", not "+-------------..."

0

1 Answer 1

1

I have figured out the solution, it was just a logical fault in my code that lead to the same output. So instead of :

typ , small , large = line.split(",")
list = [typ,small,large]

I used the csv.reader(file) function and then i implemented a simple for loop

 for line in reader:
                    table.append(line)

Also, I implemented try except to catch FileNotFoundError instead of putting it into an if statement.

1
  • please post what the issue was?
    – UpAndAdam
    Commented Dec 14, 2023 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .