「Python入門」ログファイルを出力するサンプル

# vim op_log_file.py
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import os,time

def opLogFun(log):
f=file(log_file,’a’)
date=time.strftime('%Y-%m-%d %H:%M:%S’)
record = '%s %s\n’ %(date,log)
f.write(record)

if __name__ == '__main__’:
log_file=’/tmp/log_file.log’
opLogFun('test data1’)
opLogFun('test data2’)

Python

Posted by arkgame