在 ascii 文件写入中合并预设值 Python

Incorporating preset values in ascii file writing Python

我试图在写入 ascii 文件时将预设值合并到我的脚本中,但是我一直无法找到如何执行此操作。我的预设值是之前从不同文件中提取的字符串值。

XBenchmark = (find_line_and_column('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr', 49, 4))

YBenchmark = (find_line_and_column('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr', 50, 4))

Xaxis= (find_line_and_column('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr', 51, 3))

Yaxis = (find_line_and_column('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr', 52, 3))

我正在尝试以某种方式将这些预设值合并到与此类似的文件中。

f = open('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr','w')
f.writelines(['byteorder M\n', 'layout bil\n', 'nbands 1\n', 'nbits 16\n', 'ncols 6935\n''nrows (**Yaxis**)\n''ulxmap (**Xbenchmark**)\n''ulymap 52.8704166666666\n'])
f.close()
f = open('zz_ssmv11034tS__T0001TTNATS2012021505HP001.Hdr','w')
        f.writelines(['byteorder M\n', 'layout bil\n', 'nbands 1\n', 'nbits 16\n', 'ncols '+ncols+'\n','nrows '+nrows+'\n','ulxmap '+XBenchmark+'\n','ulymap '+YBenchmark+'\n','xdim '+Xaxis+'\n','ydim '+Yaxis+'\n'])
        f.close()