擅长:python、mysql、java
<pre><code>with open('data.txt') as f:
polyShape = []
for line in f:
line = line.split() # to deal with blank
if line: # lines (ie skip them)
line = [int(i) for i in line]
polyShape.append(line)
</code></pre>
<p>会给你</p>
<pre><code>[[0, 0, 3, 50], [50, 100, 4, 20]]
</code></pre>
<p>这将适用于包含空行(或不包含空行)的文件。</p>
<p>使用<code>with</code>构造将在完成或遇到异常时自动为您关闭文件。</p>