【发布时间】:2019-07-28 13:13:57
【问题描述】:
我有一个 txt 文件,我需要读取并找到一行,并在同一个文件中更改其值。我正在使用 Python。
for file in os.listdir(path2):
if file.startswith('nasfla.in'):
crack_in = ''.join((path2, '\\', file))
file_in = open(crack_in, 'r')
with file_in:
for line in file_in:
#looking for the line that I need to change
if (str(line[1:11])) == 'schedcount':
# change the line with new value
我想更改以'schedcount' 开头的行中的内容
但我不知道如何同时读写文件。
谢谢!
【问题讨论】:
-
Read/Write text file的可能重复
标签: python