举例应用
import yagmail import traceback from config.setting import email_info, email_cc, email_to, log def send_mail(subject, content, files=None): try: smtp = yagmail.SMTP(**email_info) smtp.send(subject=subject, contents=content, to=email_to, cc=email_cc, attachments=files) except Exception as e: log.error("发送邮件失败+%s" % traceback.format_exc())
traceback的实践
import traceback try: s=1/0 except Exception as e: # print(e) #division by zero print(traceback.format_exc()) # Traceback (most recent call last): # File "D:/自动化/python-test/day11/把错误信息变成字符串.py", line 4, in <module> # s=1/0 # ZeroDivisionError: division by zeroi标签:输出,Python,traceback,smtp,cc,import,email,subject From: https://www.cnblogs.com/jiadan/p/17175799.html