我正在尝试通过 python 3.6 中的一个简单函数将 csv 文件作为附件发送。
from email.message import Message
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def email():
msg = MIMEMultipart()
msg['Subject'] = 'test'
msg['From'] = 'test@gmail.com'
msg['To'] = 'testee@gmail.com'
msg.preamble = 'preamble'
with open("test.csv") as fp:
record = MIMEText(fp.read())
msg.attach(record)
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login("test@gmail.com", "password")
server.sendmail("test@gmail.com", "testee@gmail.com", msg)
server.quit()
Run Code Online (Sandbox Code Playgroud)
调用email()产生错误expected string or bytes-like object。重新定义server.sendmail("test@gmail.com", "testee@gmail.com", msg)为server.sendmail("atest@gmail.com", "testee@gmail.com", msg.as_string()) 会导致发送电子邮件,但会在电子邮件正文中发送 csv 文件,而不是作为附件发送。谁能给我一些关于如何将 csv 文件作为附件发送的提示?
我正在开发一个程序来操作 GIS 数据,但对于这个精确的问题,我尝试围绕左下角旋转 4 个点的矩形。我有 1 个元组描述左下角:
x, y=40000,40000
我还有长度 x、长度 y、x_displacement和y_displacement。我有一个角度 ,theta以度为单位。我想将矩形向左或向右旋转最多 90 度,因此 theta 可以是 -89 到 89 度。负角度应将角向左旋转;向右为正角。我将矩形表示为:
http ://i.imgur.com/pp3hFyA.jpg
x_displacement=100
y_displacement=100
x = 40000
y = 40000
x1 = x
y1 = y + a.y_displacement
x2 = x + a.x_displacement
y2 = y + a.y_displacement
x3 = x + a.x_displacement
y3 = y
#describes the other 4 corners of the rectangle
Run Code Online (Sandbox Code Playgroud)
Coord 是一个保存 x 和 y 值的类。coords是 Coord …