title: writing to files: switch to new file after X MB file capacity
body: <p>I have millions of domains which I will send WHOIS query and record WHOIS response on some .txt file.</p>
  
  <p>I would like to set maximum capacity for a single <code>.txt</code> output file. For example, let's say I started recording responses on <code>out0.txt</code>. I want to switch to <code>out1.txt</code> if <code>out0.txt</code> is >= 100mb. Same thing goes for <code>out1.txt</code>, if <code>out1.txt</code>>=100mb then start writing to <code>out2.txt</code>and so on.</p>
  
  <p>I know that I can do <code>if</code> checks after each insertion, but I want my code to be fast: i.e. I thought if checks at each domain can slow down my code. (It will asynchronously query millions of domains).</p>
  
  <p>I imagined a try-except block could solve my issue here, like this:</p>
  
  <pre><code>folder_name = "out%s.txt"
  folder_number = 0
  
  
  folder_name = folder_name % folder_number
  f = open(folder_name, 'w+')
  
  for domain in millions_of_domains:
     try:
        response_json = send_whois_query(domain)
        f.write(response_json)
     except FileGreaterThan100MbException:
        folder_number += 1
        folder_name = folder_name % folder_number
        f = open(folder_name, 'w+')
        f.write(response_json)
  </code></pre>
  
  <p>Any suggestions will be appreciated. Thank you for your time.</p>