【发布时间】:2017-09-01 10:51:58
【问题描述】:
path = os.path.dirname(os.path.realpath(__file__))
if os.path.exists(path + '/nomore.json'):
blacklist = json.loads(open("%s/nomore.json" % (path)).read())
if cmd.lower() == "add":
try:
username = await self.bot.get_user_info(usr)
blacklist["blacklist"].append(int(usr))
json.dump(blacklist, (open("%s/nomore.json" % (path), 'w')))
await self.bot.say('`%s` added to blacklist' % (username))
except Exception as e:
await self.bot.say(e)
elif cmd.lower() == "remove":
try:
for ids in blacklist["blacklist"]:
if ids == int(usr):
blacklist["blacklist"].remove[ids]
json.dump(blacklist, (open("%s/nomore.json" % (path), 'w')
await self.bot.say('Remove invoked')
except Exception as e:
await self.bot.say(e)
我正在使用 .append() 向 JSON 对象添加值,但我不确定按值从数组中删除值的正确方法是什么。
这是 JSON 文件的样子:
{"blacklist": [225915965769121792, 272445925845106700]}
【问题讨论】:
-
什么是
await? -
在您的问题中添加输入 josn