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

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 .