Python日志类Logger使用示例,pythonlogger,import timec
Python日志类Logger使用示例,pythonlogger,import timec
import timeclass Logger: def __init__(self, filename): self.filename = filename def __call__(self, string): file = open(self.filename, 'a') file.write('[' + time.asctime() + '] ') file.write(string + '\n') file.close()log = Logger('logfile.txt')log('Starting program')log('Trying to divide 1 by 0')print 1 / 0log('The division succeeded')log('Ending program')
相关内容
- Python面向对象:在类中定义私有变量和私有方法,pyt
- 实现python的: __init__ , __sub__方法,__init___sub_,class Numbe
- python多态,重写父类方法,python多态重写,def rotate_t
- Python获得进程内存使用量的脚本,python获得进程脚本
- python 以可读并且可写方式打开文件,python打开文件,w
- python操作符重写,实现+操作符,python操作符,import str
- Instance Objects,instanceobjects,class Comple
- python中的虚函数,python函数,class Super:
- python代码注释,python注释,# a commenti
- python构造函数,,# def __i
评论关闭