title: How to make python continually save file io
body: <p>I have the following code, </p>
  
  <pre><code>def main():
  
  
  
      SucessCount = 0
      line = []
      StringList = ''
  
  
      url = "https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=&amp;match_id=1957663499"
      http = urllib3.PoolManager()
  
      for i in range(1860878309, 1860878309 + 99999999999999999 ):
          with open("DotaResults.txt", "w") as file:
              if SucessCount &gt; 70000:
                  break
              result = http.request('GET', 'https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?key=F878695BB3657028B92BCA60CEA03E16&amp;match_id=' + str(i))
              x = json.loads(result.data.decode('utf-8'))
  
  
  
              if('error' in x['result']):
                  print("Not found")
              else:
                  if validityCheck(x['result']['players']) == True and x['result']['game_mode'] == 22:
  
                      line = vectorList(x)
                      #print(line.count(1))
                      if(line.count(1) == 10 or line.count(1) == 11):
                          SucessCount += 1
                          print('Ok = ' + str(SucessCount))
                          print("MatchId = " + str(x['result']['match_id']))
                          StringList = ','.join([str(i) for i in line])
                          file.write(StringList + '\n')
  
                          if(SucessCount % 5 == 0):
  
                              file.flush()
                              file.close()
                              time.sleep(30)
  </code></pre>
  
  <p>The problem I am having is that when I press the stop button in pycharm(in normal running mode)nothing shows up in the file, even tho I am closing the file every time I loop. Does anybody know why or what i can do to fix this?</p>