title: Python loop that writes files from requests
body: <p>am trying to write a loop that gets .json from an url via requests, then writes the .json to a .csv file. Then I need it to it over and over again until my list of names (.txt file) is finished(89 lines). I can't get it to go over the list, it just get the error:</p>
  
  <pre class="lang-py prettyprint-override"><code>AttributeError: module 'response' has no attribute 'append'
  </code></pre>
  
  <p>I can´t find the issue, if I change 'response' to 'responses' I get also an error </p>
  
  <pre class="lang-py prettyprint-override"><code>with open('listan-{}.csv'.format(pricelists), 'w') as outf:
  OSError: [Errno 22] Invalid argument: "listan-['A..
  </code></pre>
  
  <p>I can't seem to find a loop fitting for my purpose. Since I am a total beginner of python I hope I can get some help here and learn more.</p>
  
  <p>My code so far.</p>
  
  <pre class="lang-py prettyprint-override"><code>#Opens the file with pricelists
  
  pricelists = []
  
  with open('prislistor.txt', 'r') as f:
      for i, line in enumerate(f):
          pricelists.append(line.strip())
  
  # build responses 
  responses = [] 
  for pricelist in pricelists: 
      response.append(requests.get('https://api.example.com/3/prices/sublist/{}/'.format(pricelist), headers=headers))
  
  #Format each response 
  fullData = [] 
  for response in responses: 
      parsed = json.loads(response.text)
      listan=(json.dumps(parsed, indent=4, sort_keys=True))
  
      #Converts and creates a .csv file.
      fullData.append(parsed['Prices'])
  
  
  
  with open('listan-{}.csv'.format(pricelists), 'w') as outf:
      dw.writeheader()
      for data in fullData: 
          dw = csv.DictWriter(outf, data[0].keys())
  
          for row in data:
              dw.writerow(row)
  
  print ("The file list-{}.csv is created!".format(pricelists)) 
  </code></pre>