title: Logging to python file doesn't overwrite file when using the mode='w' argument to FileHandler
body: <p>I have some code to set up a log in Python 2.7 (using the logging module):</p>
  <pre><code>import os
  import logging
  logger=logging.getLogger(__name__)
  logger.setLevel(logging.DEBUG)
  log_filename=os.path.join(os.path.dirname(copasi_file),os.path.split(copasi_file)[1][:-4]+'_log.log')
  handler=logging.FileHandler(log_filename,mode='w')
  formatter = logging.Formatter(&quot;%(asctime)s - %(name)s - %(levelname)s - %(message)s&quot;)
  handler.setFormatter(formatter)
  logger.addHandler(handler)
  logger.debug('debugging message')
  </code></pre>
  <p>This code works and I am getting the output, however I intend to use this log to do a lot of debugging so I want to overwrite the log file each time its run. In the <a href="https://docs.python.org/3/library/logging.handlers.html" rel="nofollow noreferrer">docs</a> say to use the <code>mode</code> keyword argument to the 'FileHandler<code>. It doesn't specify precisely *which* mode to use for overwrite file each time but I think a reasonable assumption would be</code>mode='w'`. This however doesn't work. Can anybody tell me why?</p>