How can I not read the last line of a csv file if it has simply 1 column in Python?
<p>I have 2 csv files with 4 columns like these.</p>

<pre><code>1 3 6 8\n                 1 3 7 2\n
7 9 1 3\n                 9 2 4 1\n
\n                        1 8 2 3\n
</code></pre>

<p>I only want to read rows with at least 2 columns because the row with only  \n, it isnÂ´t useful.</p>

<p>Currently, I am reading files using this:</p>

<pre><code>for line in f:
        list = line.strip("\n").split(",")
        ...
</code></pre>

<p>But, I want that lines with only 1 column should be ignored.</p>

<p>If they are legitimately comma-separated csv files, try the csv module. You will still have to eliminate empty rows, as in the other answers. For this, you can test for an empty list (which is a falsey value when evaluated as an expression in an if statement).</p>

<pre><code>import csv

with open('filename.csv' as f):
    reader = csv.reader(f)
    rows = [row for row in reader if row]
</code></pre>

<p><code>rows</code> now contains all non-empty rows in the csv file.</p>

python python-2.7 csv readfile