我正在尝试在我的脚本中包含预设值,以便在写入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()
答案 0 :(得分:0)
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()