python 读文件readline ,如何读一行删除一行

python 读文件readline ,如何读一行删除一行

python处理文件处理想要读一行删一行


回答:

python3">import shutil

counter = 1

while True:

with open('test.txt') as fin:

line = fin.readline()

if len(line) == 0:

break

print(line.strip())

with open(f'delete-{counter}-line.txt', 'w+') as fout:

shutil.copyfileobj(fin, fout)

shutil.copy(f'delete-{counter}-line.txt', 'test.txt')

counter += 1

所以你到底想干啥?

以上是 python 读文件readline ,如何读一行删除一行 的全部内容, 来源链接: utcz.com/p/938018.html

回到顶部