本文主要是介绍python.snippet,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
python 的代码片段, 拿出来分享。
#!/usr/bin/env python
# -*- coding: utf-8 -*-"""
desc
"""# ---------
# Change Logs:
#
# ---------__author__ = 'Pidong'
__email__ = '***'
__version__ = '1.0.1'
__status__ = 'Production'import sys
# reload(sys)
# sys.setdefaultencoding('utf-8')
import argparse
import loggingdef log(file_name, logger_name='lipidong', verbose=False):logger = logging.getLogger(logger_name)formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")handler = logging.FileHandler(file_name)handler.setFormatter(formatter)logger.addHandler(handler)logger.setLevel(logging.INFO)if verbose:console = logging.StreamHandler()console.setLevel(logging.INFO)logger.addHandler(console)return loggerdef get_args():parser = argparse.ArgumentParser(prog='desc')parser.add_argument('--input_file', help='')parser.add_argument('--log', help='log file, default=log.log', default='log.log')parser.add_argument("--verbose", help="increase output verbosity",action="store_true")if len(sys.argv) == 1:parser.print_help()exit()return parser.parse_args()def test(input_file):"""TODO: Docstring for test.:input_file::returns: None"""logger.info(input_file)def main():args = get_args()input_file = args.input_filelog_file = args.logverbose = args.verboseglobal loggerlogger = log(log_file, verbose=verbose)test(input_file)if __name__ == '__main__':main()
这篇关于python.snippet的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!