def open_logfile(filename, mode='a'):
    filename = os.path.expanduser(filename)
    filename = os.path.abspath(filename)
    dirname = os.path.dirname(filename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
    exists = os.path.exists(filename)

    log_fp = open(filename, mode)
    if exists:
        log_fp.write('%s\n' % ('-' * 60))
        log_fp.write('%s run on %s\n' % (sys.argv[0], time.strftime('%c')))
    return log_fp
Open the named log file in append mode.
dataset/ETHPy150Open balanced/status.balancedpayments.com/venv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg/pip/basecommand.py/open_logfile