python - TypeError: write() 参数必须是 str,而不是 int
问题描述
下面是我的代码
for a in list(range(1,100)):
print(a)
with open("C:/Users/me/Downloads/Documents/lala",mode="w")as f:
print(f.write(a))
错误是:
TypeError: write() argument must be str, not int
解决方案
您需要在编写之前将 a 转换为字符串
str(a)
您还应该删除 print 调用,因为您的文件操作中不应该有任何可打印的内容
f.write(str(a))
推荐阅读
- c++ - 什么是查看函数是否公开的快速方法?
- google-cloud-datastore - 如何定期更新 Google Datastore 中的适量数据(约 250 万条条目)?
- python - 如何在位于 tk.Canvas 内的 tk.Frame 中添加两个小部件?
- php - 使用 REST API 发起对 Twilio 注册 SIP 的调用
- tensorflow - 无法使用 tensorflow-gpu 1.8.0 conda 包访问 GPU
- java - 在 Java Spring 中以 REST 方法返回后执行清理操作
- wordpress - 生成电子邮件优惠券 Wordpress
- c# - 如何在 SAP Crystal 报表中格式化阿拉伯日期名称 ar-AR 或 en-EN
- javascript - Animejs在滚动上动画文本
- transactions - 我可以将 JTA 与微服务一起使用吗?