我有此代码:
def yaml_processor(period):
filepath_reg = "../public/log/testing.log.yaml"
data = yaml_loader(filepath)
data = data.get(period)
for team, key in data.iteritems():
file = open("test.log.yaml", 'w')
file.write('%team %period\n')
file.close()
print(team, period)
它不想写它们file.write('{team}, {period}\n')
,但是可以完美地打印值...
我在这里做什么错了?
答案 0 :(得分:1)
您需要学习string formatting。
尝试将file.write('%team %period\n')
替换为
file.write('{} {}\n'.format(team, period))
答案 1 :(得分:1)
如果您使用的是最新版本的Python(3.6或更高版本),则可以利用f-strings:
with open("test.log.yaml", 'w') as file:
file.write(f'{team} {period}\n')
答案 2 :(得分:0)
您将在循环的每次迭代中打开文件,该循环将删除先前的值。只需将open和close语句移出循环即可。
HttpServerRequest request = RoutingContext.request();
MultiMap params = request.params();
List<String> param = params.getAll("personId");
Here you can get list of personId. URI be like
localhost:8081/myApi?personId=1&personId=2&personId=3