title: How to use string as input for csv reader without storing it to file
body: <p>I'm trying to loop through rows in a <code>csv</code> file. I get <code>csv</code> file as <code>string</code> from a web location. I know how to create <code>csv.reader</code> using <code>with</code> when data is stored in a file. What I don't know is, how to get rows using <code>csv.reader</code> without storing <code>string</code> to a file. I'm using Python 2.7.12.</p>
  
  <p>I've tried to create <code>StringIO</code> object like this:</p>
  
  <pre><code>from StringIO import StringIO
  
  csv_data = "some_string\nfor_example"
  with StringIO(csv_data) as input_file:
      csv_reader = reader(csv_data, delimiter=",", quotechar='"')
  </code></pre>
  
  <p>However, I'm getting this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "scraper.py", line 228, in &lt;module&gt;
      with StringIO(csv_data) as input_file:
  AttributeError: StringIO instance has no attribute '__exit__'
  </code></pre>
  
  <p>I understand that <code>StringIO</code> class doesn't have <code>__exit__</code> method which is called when <code>when</code> finishes doing whatever it does with this object. </p>
  
  <p>My answer is how to do this correctly? I suppose I can alter <code>StringIO</code> class by subclassing it and adding <code>__exit__</code> method, but I suspect that there is easier solution.</p>
  
  <p>Update:</p>
  
  <p>Also, I've tried different combinations that came to my mind:</p>
  
  <pre><code>with open(StringIO(csv_data)) as input_file:
  
  with csv_data as input_file:
  </code></pre>
  
  <p>but, of course, none of those worked.</p>