擅长:python、mysql、java
<p><code>readlines()</code>将返回文件中所有行的列表,因此<code>lines</code>是一个列表。你可能想要这样的东西:</p>
<pre><code>for line in f.readlines(): # Iterates through every line and looks for a match
#or
#for line in f:
match = re.findall('[A-Z]+', line)
print match
</code></pre>
<p>或者,如果文件不太大,可以将其作为单个字符串获取:</p>
<pre><code>lines = f.read() # Warning: reads the FULL FILE into memory. This can be bad.
match = re.findall('[A-Z]+', lines)
print match
</code></pre>