我想发送电子邮件与附加的jpg文件时,它被创建,然后删除该文件,在文件夹中没有留下任何jpg文件。文件的实际名称会随着日期和时间而改变,但我不知道它是什么。我试过用这个
#Email body
rstime = datetime.datetime.now().strftime('%d %b %Y at %H:%M:%S')
body = 'Picture saved of movement at front of house ' + str(rstime)
msg.attach(MIMEText(body, 'plain'))
fp = open('/mnt/usb/motion/*.jpg', 'rb')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)
#remove file after emailing
os.remove('/mnt/usb/motion/*.jpg')
这给了我一个错误- IOError:[Errno 2]没有这样的文件或目录:'/mnt/usb/motion/*.jpg'
我的代码怎么了?如果我输入文件名,它可以工作,但我想使用通配符。你知道吗
看看fnmatch
但是
glob
模块看起来更好,因为在本例中不必join
文件路径和文件名。你知道吗不能以这种方式使用通配符。如果两个文件匹配通配符,会发生什么情况?两个文件应该在同一个对象中打开吗?你知道吗
您可以将通配符与python
glob
模块一起使用:相关问题 更多 >
编程相关推荐