<p>这是我在StackOverflow上的第一篇帖子,如果太含糊,我深表歉意。
基本上,我有很多从程序输出的文件,我正在尝试自动收集所有数据的过程。你知道吗</p>
<p>我只需要以打印格式返回字符串的值。我已经设法做到了。但是,我还想在新打印的文件上创建一列,告诉我字符串来自哪个文件。你知道吗</p>
<p>我只用了6个小时。。。所以任何帮助都将非常感谢!你知道吗</p>
<p>文件内容的片段:</p>
<pre><code> GROWTH DIRECTION = 0 0 1
SLICE SHIFT 5 = 0.00 ANGSTROMS
LATTICE ENERGY = -21.40 KCAL/MOL
SLICE ENERGY = -21.40 KCAL/MOL
ATTACHMENT ENERGY = 0.00 KCAL/MOL
SURFACE ENERGY = 0.00
-------------------------------------------
</code></pre>
<p>这是我到目前为止的情况。你知道吗</p>
<pre><code># This script is to be used to pull out lines from strings.
import re # Standard Regular expression module
lattE = open("TestFile.txt", "r") # opens the assigned file
lattEW = open("Lattice_Energies2.txt", "w") # Writes a new document to include all the lines that use LATTICE
for line in lattE: # looks through every line in the file
if re.match("(.*)(L)ATTICE(.*)", line): #searches the lines for LATTICE
print >>lattEW, line, # Prints the lines
</code></pre>
<p>电流输出:</p>
<pre><code> LATTICE ENERGY = -21.40 KCAL/MOL
LATTICE ENERGY = -21.40 KCAL/MOL
</code></pre>