Python 某些项目的格式不正确,但其余项目的格式不正确

Python 某些项目的格式不正确,但其余项目的格式不正确,python,Python,我不知道为什么有些项目的格式不正确,短的名字看起来不错,但长的名字会把它们自己弄丢 正在按照您的评论进行修复;)AlexisDevarenes我尝试过获得ValueError:未知格式代码's'用于'int'类型的对象如果这有帮助,请将答案标记为正确:)此外,如果您仍然存在问题,请更新您的问题。 prices = {} groceries = [] file = open("grocery_store_price_list.txt", "r") for strx in file: s

我不知道为什么有些项目的格式不正确,短的名字看起来不错,但长的名字会把它们自己弄丢


正在按照您的评论进行修复;)AlexisDevarenes我尝试过获得ValueError:未知格式代码's'用于'int'类型的对象如果这有帮助,请将答案标记为正确:)此外,如果您仍然存在问题,请更新您的问题。
prices = {}
groceries = []

file = open("grocery_store_price_list.txt", "r")
for strx in file:
    strs = list(filter(None, strx.strip().split(" ")))
    prices[strs[0]] = [strs[1]], [strs[2]]
file.close()

file = open("my_personal_gro_list.txt", "r")
for strx in file :
    strs = list(filter(None, strx.strip().split(" ")))
    groceries.append([strs[1], strs[0]])

headings = "{:6s} {:9s} {:6s} {:7s} {:6s}".format("item", "qty", "unit", "cost", "total")

print(headings)

finalCost = 0


for strs in groceries:
    item = strs[0]
    qty = int(strs[1])
    unit = prices[strs[0]][1]
    cost = float(prices[strs[0]][0][0])
    total = qty*cost

    finalCost += total

    print(item, qty, unit, cost, total,)
print("{item}\t{qty}\t{unit}\t{cost}\t{total}".format(item=item, qty=qty, unit=unit, cost=cost, total=total))