When working with files in Python2.7 (using the iPython console of the Spyder IDE, I'm not sure if this behavior is general to all IDE's) I've noticed that even if you use a with
block, the active python shell retains the file in an open state until the shell is closed. This behavior is extremely annoying as I cant simply delete a file without first closing the current Python session. Is there a way to bypass this behavior?
Here's the code that I'm running to observe this behavior:
if __name__=='__main__':
logger=logging.getLogger('CopasiTools')
logger.setLevel(logging.DEBUG)
log_filename=os.path.join(os.getcwd(),'fileQuestionExample.log')
handler=logging.FileHandler(log_filename,mode='w')
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.debug('example debug')