title: Python loop that writes files from requests with going trough a list
body: <p>I 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 picks the bottom name of my list and then quits. I need it to go through and basically create 89 files, with the corrects urls. The other functions works properly, but it only does it once.</p>
  
  <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 </p>
  
  <pre class="lang-py prettyprint-override"><code>#Opens the file with pricelists
  
  with open('prislistor.txt', 'r') as f:
      for i, line in enumerate(f):
          pricelists = (line.strip())
  
  response = requests.get('https://api.example.com/3/prices/sublist/{}/'.format(pricelists), headers=headers)
  
  #Formats it
  parsed = json.loads(response.text)
  
  listan=(json.dumps(parsed, indent=4, sort_keys=True))
  
  #Converts and creates a .csv file.
  data = parsed['Prices']
  
  with open('listan-{}.csv'.format(pricelists), 'w') as outf:
      dw = csv.DictWriter(outf, data[0].keys())
      dw.writeheader()
  
      for row in data:
          dw.writerow(row)
  
  print ("The file list-{}.csv is created!".format(pricelists))
  </code></pre>