Dan*_*iel 0 python string integer for-loop write
我有2个文件:
text.txt
和:
main.py
在main.py,我有以下代码:
for i in range(1,4097):
i = str(i)
file = open("text.txt","w")
file.write(i)
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我想从1生成所有号码- 4096,但是当我运行该脚本,它只是写4096在text.txt。
我如何在里面写数字 1 - 4096 text.txt?
(顺便说一句,我做i了一个字符串 ( str()) 因为它有我和错误说 Python 只能写字符串而不是 Intigers:
Traceback (most recent call last):
File "d:\path\app.py", line 14, in <module>
file.write(i)
TypeError: write() argument must be str, not int
Run Code Online (Sandbox Code Playgroud)
)
谢谢
-D一个n我e升