我只是想知道,我如何强制python停止将我的.json文件写入一行?我不知道该怎么办,所以我在这里问.我已经尝试将write命令更改with open('manifest.json', 'wb') as f:为with open('manifest.json', 'w') as f:但仍然写入一行?
import json
with open('manifest.json', 'r') as f:
json_data = json.load(f)
json_data['server-version'] = "xxxx-x.x.x"
with open('manifest.json', 'w') as f:
f.write(json.dumps(json_data))
print('Successful.')
Run Code Online (Sandbox Code Playgroud)
如果我在询问时出错,请更正.我是stackoverflow的新手:)
我正在尝试从外部脚本向路由器发送数据,并返回错误 TypeError: Cannot read property 'send' of undefined
这是代码
app.js
var Cake = require('./modules/cake');
router.get('/cakes', function(req, res) {
Cake.getCake();
})
Run Code Online (Sandbox Code Playgroud)
cake.js
module.exports = {
getCake: function (req, res) {
request({
url: "http://get.cakes/json",
json: true
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.send(body);
}
});
}
};
Run Code Online (Sandbox Code Playgroud)
请注意,这http://get.cake/不是一个真实的网站.这个问题无关紧要.