我有一个打开的文件,我想搜索,直到在一行的开头找到特定的文本短语。然后我想用“句子”覆盖那一行
sentence = "new text" "
with open(main_path,'rw') as file: # Use file to refer to the file object
for line in file.readlines():
if line.startswith('text to replace'):
file.write(sentence)
我越来越:
Traceback (most recent call last):
File "setup_main.py", line 37, in <module>
with open(main_path,'rw') as file: # Use file to refer to the file object
ValueError: must have exactly one of create/read/write/append mode
我怎样才能让它工作?
幕布斯6054654
哆啦的时光机
相关分类