python - 如何让用户输入的详细信息进入 python 文本文件中的新行?
问题描述
'''volunteerList.append([ [name], [coinType], [weight], [correct], "\n"])'''
上面的代码是我尝试过的代码,但输入的细节最终在同一行,并删除了最后一组输入的细节。
解决方案
我不确定此示例中文件的位置,但您希望这样做不会覆盖文件:
name = "A"
coinType = "B"
weight = 99
correct = False
your_list = [ name, coinType, weight, correct]
text = "\n" + " ".join([str(x) for x in your_list])
with open("output.txt", "a") as f:
f.write(text)
推荐阅读
- java - 在 JAVA 中显示格式 XX:00
- asp.net-mvc - 将模型传递给局部视图不起作用
- java - 没有找到 org.apache.http.annotation.NotThreadSafe 的类文件,我该如何在 intellij idea 上修复它?
- c# - string.split 从大字符串中解析 url
- angular - 如何使用 *ngFor 指令从 Ionic 3(Cordova、Ionic 3、Angular 5)上的存储中获取数据
- python - 以不同的顺序将日期时间转换为 UTC
- fortran - Fortran arctan 子例程未按预期工作
- ios - 无法让 API 调用及时运行 tableview swift 4 xcode 9
- python - 在我的链表实现中分配之前引用的错误局部变量“节点”?
- javascript - Node.js Express - res.render() 如何在未将数据传递给它时使用数据创建 html?