我想逐行读取输入文件,然后修改一行并将更改写回同一文件
问题是回写后,我失去了返回该行的权限,并且所有数据都放在一行中
open(bludescFilePath, 'a+') as blu:
blu_file_in_lines = blu.readlines()
for line in blu_file_in_lines:
if "Length" in line:
blu_file_in_lines[13] = line.replace("0x8000",str(size))
with open(bludescFilePath, 'w') as blu:
blu.write(str(blu_file_in_lines))
答案 0 :(得分:2)
编辑
好的,缺少的是for循环。
with open(bludescFilePath, 'w') as blu:
for line in blu_file_in_lines:
blu.write(str(line))