0
辞書を.txtファイルに順番に書き込む必要があるコードがあります。私の辞書のソートされた方法で辞書からテキストファイルに書き込む(Python)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
マイ内容:
ここwith open("Items.txt", "w+") as file:
for item in sorted(orders):
file.write(item + "," + ",".join(map(str,orders[item])) + "\n")
file.close
print("New stock level to file complete.")
受注は、私がこのようなタイプのエラーを取得するItems.txt
に私はこれを実行するたびに書きたい私の辞書です次のとおりです。
orders[int(code)] = [str(name),int(current_stock),int(re_order),int(target_stock),float(price)]
この問題をお手伝いできますか?私はすべての内容が文字列ではないと思うが、私はどのように辞書の内容を文字列に変更するのか分からない。
PS:後で整数を使用する必要があるため、辞書の内容を文字列に変更できません。
ありがとうございました!出来た –