2024-04-25 03:50:02 发布
网友
我有两个文件:
text
及
program.py
我将文本插入我的
使用以下行创建文件:
inp=input('Text by the user') with open("text.py", "a") as myfile: myfile.write(inp)
如何使程序删除文本中的行,使其显示:
text2
不是
text1 text2
什么时候跑两次
with open("text.txt", "w") as file: file.write(input("Write on file> "))
以写入模式(w)而不是追加模式(a)打开。这将在写入文件之前清空该文件
w
a
inp=input('Text by the user') with open("text.py", "w") as myfile: myfile.write(inp)
更少的代码
以写入模式(
w
)而不是追加模式(a
)打开。这将在写入文件之前清空该文件相关问题 更多 >
编程相关推荐