我写的脚本读输入文件,取值,需要写在输出模板的特定位置(行),我是绝对菜鸟,不能这样做。它要么写入输出的第一行,要么写入最后一行。在
opened file as 'r+'
used file.write(xyz) command
混淆了如何向python解释如何写入特定行,例如第17行(输出模板中的空行)
编辑:
with open (MCNP_input, 'r+') as M:
line_to_replace = 17
lines = M.readlines()
if len(lines) > int (line_to_replace):
lines[line_to_replace] = shape_sphere + radius + '\n'
M.writelines(lines)
你可以先读取文件,然后写入某一行。在
相关问题 更多 >
编程相关推荐