[英]How to write to a text file without adding new line
How to do the following code, but to a text file instead of printing to console. 如何执行以下代码,但将其转换为文本文件而不是打印到控制台。
print("test",end="") 打印( “测试”,结束= “”)
I tried to execute this code, but its not working. 我试图执行此代码,但无法正常工作。
file.write("test",end="") file.write( “测试”,结束= “”)
file.write() can't accept more than 1 argument (which is the string that should be written to the file) file.write()不能接受多个参数(这是应写入文件的字符串)
with open("test.txt", "w+") as file:
for i in range(10):
file.write("test")
The result in test.txt: testtesttesttesttesttesttesttesttesttest test.txt中的结果:testtesttesttesttesttesttesttesttesttesttest
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.