擅长:python、mysql、java
<p>更简单的方法</p>
<p>演示:</strong></p>
<pre><code>total = 0
num_recs = 0
with open(filename) as infile: #Read File
for line in infile: #Iterate Each line
if "|" in line: #Check if | in line
total += int(line.strip().split("|")[-1]) #Extract value and sum
num_recs += 1
print(total, num_recs)
</code></pre>