Python3
1import json, codecs 2f = codecs.open('tickets.json', 'r', 'utf-8') 3Ti = json.load(f) 4tget = Ti["name"] 5cTi = int(tget) - 1 6Ti["name"] = cTi 7if cTi <= 0: 8 Ti.pop("name") 9 agim = '招待券が残り0枚になりました。' 10 f.close() 11elif cTi > 0: 12 agim = '招待券は残り' + cTi + '枚です。' 13 f.close() 14else: 15 f.close() 16 print('エラー')
JSON
1{ 2 "name": "5" 3}
tgetは文字列で1は数値のはずで、intにtegtを数値化すると
must be str, not int
が出てしまい、
tget - 1 をすると(文字列、数値の置換なし)以下のエラーが出るので詰んでます...
unsupported operand type(s) for -: 'str' and 'int'
ちなみにどちらも文字列(str)にしても、
unsupported operand type(s) for -: 'str' and 'str'
というエラーが出ます。
どなたか解決法をご伝授ください。
回答2件
あなたの回答
tips
プレビュー