[英]Replacing Text in another file with a separate program
我有兩個文件:
文字
和
程序.py
我將文本插入到我的
文字
使用以下行的文件:
inp=input('Text by the user')
with open("text.py", "a") as myfile:
myfile.write(inp)
我怎樣才能讓程序刪除文本中的行,它說:
文本 2
不
文本 1 文本 2
什么時候跑兩次?
以寫入模式 ( w
) 而不是追加模式 ( a
) 打開。 這會在寫入文件之前清空文件。
inp=input('Text by the user')
with open("text.py", "w") as myfile:
myfile.write(inp)
with open("text.txt", "w") as file:
file.write(input("Write on file> "))
def write_input(file):
"Get and input and writes it to a file"
inp = input("Write something: ")
with open(file, "w") as file:
file.write(inp)
return inp
write_input("mytext.txt")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.