1. 程式人生 > >python3+requests介面自動-配置檔案

python3+requests介面自動-配置檔案

1.cfg.ini開啟,這裡寫配置檔案內容

[email]
smtp_server = smtp.qq.com
port = 456
sender = [email protected]

;psw是郵箱的授權碼
psw = xxx


receiver = [email protected]

2.用readConfig.py讀取配置檔案
 1 import os
 2 import ConfigParser
 3 
 4 cur_path = os.path.dirname(os.path.realpath(__file__))
 5 configPath = os.path.join(cur_path,"
cfg.ini") 6 conf = ConfigParser.ConfigParser() 7 conf.read(configPath) 8 9 smtp_server = conf.get("email","smtp_server") 10 11 sender = conf.get("email","sender") 12 13 psw = conf.get("email","psw") 14 15 receiver = conf.get("email","receiver") 16 17 port = conf.get("email","port")

3.讀取的內容就是傳入第二步操作裡面需要呼叫郵箱的配置資訊