Python3.0与2.X版本的区别实例分析(2)
12.python3.0中添加了logging module,给我的感觉类似于Java中的log4j,直接看代码: import os, platform, logging if platform.platform().startswith('Windows'): logging_file = os.path.
12.python3.0中添加了logging module,给我的感觉类似于Java中的log4j,直接看代码:
import os, platform, logging
if platform.platform().startswith('Windows'):
logging_file = os.path.join(os.getenv('HOMEDRIVE'),
os.getenv('HOMEPATH'), 'test.log')
else:
logging_file = os.path.join(os.getenv('HOME'), 'test.log')
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s : %(levelname)s : %(message)s',
filename = logging_file,
filemode = 'w',
)
logging.debug("Start of the program")
logging.info("Doing something")
logging.warning("Dying now")
希望本文所述能对大家理解Python3.0与Python2.X一些区别性的用法有所帮助。
精彩图集
精彩文章






