发现那些好用的Python模块

模块名:yagmail        (pip install yagmail) 

功能:发邮件

import yagmail

#链接邮箱服务器
yag = yagmail.SMTP( user="[email protected]", password="1234", host='smtp.126.com')

# 邮箱正文
contents = ['This is the body, and here is just text http://somedomain/image.png',
            'You can find an audio file attached.', '/local/path/song.mp3']

# 发送邮件
yag.send('[email protected]', 'subject', contents)

代码转自虫师大神:http://www.cnblogs.com/fnng/p/7967213.html

send方法可以这么用 多个收件人和多个附件

yag.send(to=['[email protected]', ''[email protected]'], subject='subject', contents='contents', attachments=[path1, path2])


模块名:pyinstaller        (pip install pyinstaller)

功能:打包py文件 & Python运行环境 为可执行文件(如:exe)

py代码调用pyinstaller,将.py文件转换成exe文件(推荐)

当然也可以在TargetOpinionMain.py同目录下创建一个转换文件TargetPy2exe.py:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = '将TargetOpinionMain python项目转换为exe文件'
__author__ = '皮'
__email__ = '[email protected]'
"""
from PyInstaller.__main__ import run

if __name__ == '__main__':
    opts = ['TargetOpinionMain.py', '-F']
    # opts = ['TargetOpinionMain.py', '-F', '-w']
    # opts = ['TargetOpinionMain.py', '-F', '-w', '--icon=TargetOpinionMain.ico','--upx-dir','upx391w']
    run(opts)

效果同命令行执行是一样的,只不过使用IDE执行这个转换代码,出错的话会有出错栈提示,可以很快到达出错位置;并且生成的build、dist目录就在本目录下,不用担心在命令行中执行目录错乱,找不到或者搞混dist目录。

代码转自:https://blog.csdn.net/pipisorry/article/details/50620122

猜你喜欢

转载自blog.csdn.net/wuchenlhy/article/details/79855248