【发布时间】:2023-03-08 19:04:01
【问题描述】:
基本上我需要它来查找用户输入和包含该单词的行以删除整行。我不知道该怎么做并且被卡住了。我可以帮忙吗
def delStock(f):
count = 0
itemRemove = input("""
Please enter the item you wish to delete.
: """)
with open("CurrentStock.txt", "r") as f:
lines = f.readlines()
with open('CurrentStock.txt', "w") as f:
for line in lines:
if line.strip(itemRemove) != itemRemove:
f.write(line)
是的,我知道这段代码现在真的坏了,所以我需要帮助!
【问题讨论】: