1
我想從output.txt的線121-136讀取並保存在同一格式zxyr.txt.File看起來是這樣的:如何從特定行讀取文件並寫入輸出?
>ZYXR //74
-6.440208621086e+03 -4.758666382870e+03 -3.995858566350e+03 -4.934315690511e+03 -5.049765912718e+03
-4.323241464318e+03 -4.246930447741e+03 -3.836596391287e+03 -3.357569224670e+03 -2.955821531683e+03
-2.579438902492e+03 -2.291910045847e+03 -1.831407086906e+03 -1.630707014227e+03 -1.376537942484e+03
我的代碼
from __future__ import with_statement
inFile = open('output.txt','r')
outFile = open('zxyr.txt', 'w')
lines=[121, 136]
i=0
for line in inFile:
if i in lines:
counter = str(int(inFile.read().strip())
outFile.seek(0)
outFile.write(counter)
i+=1
但
File "ex1.py", line 12
outFile.seek(0)
^
SyntaxError: invalid syntax
我的代碼有什麼問題?
我可以用這個多行間隔(121,136)螞蟻后者(184,206)? –
不,不幸的是,這種方法適用於單一範圍,稍微不同的方法雖然可行,但我會更新。 –