title: Explicit way to close file in Python
body: <p>Please look at the following code:</p>
  
  <pre><code>for i in xrange(1,5000):
      with open(r'test\test%s.txt' % i, 'w') as qq:
          qq.write('aa'*3000)
  </code></pre>
  
  <p>It seems to be written according to all Python rules; files are closing after using. Seems to. But in fact it seems to recommend(!) system to close file, not to close it explicitly because when I'm looking on Resource monitor it shows a lot of open files . It gives me a lot of problems because in my script I use a lot of files and after a long time I got "Too many open files" error despite of 'closing' it from source code.</p>
  
  <p>Is there some way to explicitly close file in Python? Or how can I check whether the file was really(!) closed or not?</p>
  
  <p><strong>Update</strong>: I've just tried with another monitoring tool - Handle from Sysinternals and it shows all correct and I trust it. So, it may be problem in Resource monitor itself.</p>
  
  <p>Screenshot which shows files opened:</p>
  
  <p><img src="https://i.stack.imgur.com/gsk8g.png" alt="Resource Monitor with the script running"></p>