title: Append lists from different csv files in Python
body: <p>I am trying to append several lists each from a different csv files in Python. Here is the code I am using:</p>
  <pre><code>from_ls = [1,2,3,4,5]
  to_ls = [2,3,4,5,6]
  mylists = []
  for i in range(len(from_ls)):
      from_ = from_ls[i]
      to_ = to_ls[i]
      print(str(from_)+'-'+str(to_))
      f = 'data'+str(from_)+'to'+str(to_)+'.csv'
      if os.path.exists(f):
          with open('data'+str(from_)+'to'+str(to_)+'.csv') as f:
              reader = csv.reader(f)
              mylists.extend(reader)
          print('file '+f+' append successfully')
      else:
          print('file '+f+' not found')
  </code></pre>
  <p>It gives me the following error:</p>
  <pre><code>1-2
  Traceback (most recent call last):
    File &quot;&lt;stdin&gt;&quot;, line 12, in &lt;module&gt;
  TypeError: can only concatenate str (not &quot;_io.TextIOWrapper&quot;) to str
  </code></pre>
  <p>I know that <code>f = 'data'+str(from_)+'to'+str(to_)+'.csv'</code> creates an <code>_io.TextIOWrapper</code> but I don't know how to turn it into a string so that I can read the file.</p>
  <p>I have tried to read the csv files individually as below and it works fine:</p>
  <pre><code>i=0
  from_ = from_ls[i]
  to_ = to_ls[i]
  with open('data'+str(from_)+'to'+str(to_)+'.csv') as f:
      reader = csv.reader(f)
      mylists = list(reader)
  </code></pre>