Selectively feeding python csv class with lines
<p>I have a csv file with a few patterns. I only want to selectively load lines into the csv reader class of python. Currently, csv only takes a file object. Is there a way to get around this?<br>
In other words, what I need is:</p>

<pre><code>with open('filename') as f:
    for line in f:
        if condition(line):
            record = csv.reader(line)
</code></pre>

<p>But, currently, csv class fails if it is given a line instead of a file object.</p>

<pre><code>import shlex
lex = shlex.shlex('"sreeraag","100,ABC,XYZ",112',',', posix=True)
lex.whitespace += ','
lex.whitespace_split = True
print list(lex)
</code></pre>

<p>yields</p>

<pre><code>['sreeraag', '100,ABC,XYZ', '112']
</code></pre>

python csv