日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

configparser logging

發(fā)布時間:2023/12/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 configparser logging 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
configparser模塊 # 該模塊適用于配置文件的格式與windows ini文件類似,可以包含一個或多個節(jié)(section),每個節(jié)可以有多個參數(shù)(鍵=值)。 import configparser config = configparser.ConfigParser() config['bitbucket.org'] = {'User':'hg'} config['topsecret.server.com'] = {'Host Port':'50022','ForwardX11':'no'} with open('example.ini', 'w') as configfile:config.write(configfile) #---------------------------查找文件內(nèi)容,基于字典的形式 config = configparser.ConfigParser() config.read('example.ini') print(config.sections()) print('bytebong.com' in config) # False print(config['bitbucket.org']["user"]) # hg for key in config['bitbucket.org']:print(key) # 注意,有default會默認default的鍵 print(config.options('bitbucket.org')) # 同for循環(huán),找到'bitbucket.org'下所有鍵 print(config.items('bitbucket.org')) # 找到'bitbucket.org'下所有鍵值對 print(config.get('bitbucket.org','compression')) # yes get方法Section下的key對應的value #---------------------------增刪改 config = configparser.ConfigParser() config.read('example.ini') config.add_section('yuan') # 增加section config.remove_section('bitbucket.org') # 刪除一個section config.remove_option('topsecret.server.com',"forwardx11") # 刪除一個配置項 config.set('topsecret.server.com','k1','11111') config.set('yuan','k2','22222') config.write(open('new2.ini', "w"))import logging # logging.basicConfig(level=logging.WARNING, # format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', # datefmt='%a, %d %b %Y %H:%M:%S') # logging.debug('debug message') # 低級別的 # 排錯信息 # logging.info('info message') # 正常信息 # logging.warning('warning message') # 警告信息 # logging.error('error message') # 錯誤信息 # logging.critical('critical message') # 高級別的 # 嚴重錯誤信息 # # basicconfig 簡單 能做的事情相對少 # 中文的亂碼問題 # 不能同時往文件和屏幕上輸出 # # 配置log對象 稍微有點復雜 能做的事情相對多 import logging logger = logging.getLogger()        #logger.setLevel(logging.DEBUG) fh = logging.FileHandler('log.log',encoding='utf-8') # 創(chuàng)建一個文件控制對象 sh = logging.StreamHandler() # 創(chuàng)建一個屏幕控制對象 formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') formatter2 = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s [line:%(lineno)d] : %(message)s') # 文件操作符 和 格式關聯(lián) fh.setFormatter(formatter) sh.setFormatter(formatter2) # logger 對象 和 文件操作符 關聯(lián) logger.addHandler(fh) logger.addHandler(sh) logging.debug('debug message') # 低級別的 # 排錯信息 logging.info('info message') # 正常信息 logging.warning('警告錯誤') # 警告信息 logging.error('error message') # 錯誤信息 logging.critical('critical message') # 高級別的 # 嚴重錯誤信息

?

轉載于:https://www.cnblogs.com/ming-yuan/p/9536876.html

總結

以上是生活随笔為你收集整理的configparser logging的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。