python - 写入文件 .txt
问题描述
这就是输出在文本文件中的样子
Ray Holt
5 5 0 0 100 15
Jessica Jones
12 0 6 6 50 6
Johnny Rose
6 2 0 4 20 10
Gina Linetti
7 4 0 3 300 15
这个数字是我必须创建的游戏的结果。
我的问题是,如何将字符串和整数结果写入文本文件?我试过这个
def write_to_file(filename, player_list):
output = open(filename, "w")
for player in player_list:
output.write(str(player))
但输出是
Ray Holt 5 5 0 0 100 15Jessica Jones 12 0 6 6 50 6Johnny Rose 6 2 0 4 20 10Gina Linetti 7 4 0 3 300 15Khang 0 0 0 0 100 0
他们在 1 行
请帮我!非常感谢各位
解决方案
用这个:
def write_to_file(filename, player_list):
output = open(filename, "w")
for player in player_list:
output.write(str(player)+'\n')
output.close()
推荐阅读
- jquery - 仅允许文本框上的字母,即使用户使用 jQuery 复制+粘贴不起作用
- python - python3 shell模式可以输出一些字节的utf-8字符,而不能输出其他一些字节,这是什么原因?
- node.js - GET 请求 401(未经授权)
- c# - 如何根据兄弟节点的值获取 XML 节点?
- sql-server - 两个 (SELECT TOP 1 +1 ) 语句和两个 INSERTS 同时
- c++ - 如何在 sdl2 中阻止线性矩形运动口吃
- javascript - React Failed prop type: value without onChange handler
- asp.net - Word VBA / 宏在服务器 Application.Run、ASP.NET、DCOM 上运行
- flask - Flask-PyMongo 查询数据库
- python - 从两种不同的方法计算召回率和准确率的不同结果