python代码片段

获取当前脚本的路径

import sys, os path = os.path.realpath(sys.argv[0]) print(os.path.split(path))

【python代码片段】


使用日志库
def CreateLogger(loggername, filename): import logging lger = logging.getLogger(loggername) lger.setLevel(logging.DEBUG) fhd = logging.FileHandler(filename, 'w') fhd.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') fhd.setFormatter(formatter) lger.addHandler(fhd) return lger



    推荐阅读