好吧,我的java脚本机器人有一行代码,我正试图用python重新创建它!如果有人能告诉我我需要做什么的话。甚至是如何用python编写它,我会非常感激!在
const fs = require("fs");
let points = JSON.parse(fs.readFileSync("./points.json", "utf8"));
client.on("message", message => {
if (message.author.bot) return; // always ignore bots!
// if the points don"t exist, init to 0;
if (!points[message.author.id]) points[message.author.id] = {
points: 0,
level: 0
};
points[message.author.id].points++;
// And then, we save the edited file.
fs.writeFile("./points.json", JSON.stringify(points), (err) => {
if (err) console.error(err)
});
});
如果可能的话,我想继续使用.json!但如果他们有更好的方法,请告诉我!<;3个
对于python2,可以使用
^{pr2}$open
打开文件。使用r
或w
标志,具体取决于您要读还是写。例如:对于json,使用内置库https://docs.python.org/2/library/json.html
这个片段展示了如何将json对象写入文件
相关问题 更多 >
编程相关推荐