使用glob只从文件夹中获取txt和png文件

时间:2017-12-14 04:31:19

标签: python glob

我试图只将文件夹中的文本文件和图像作为附件发送到目前为止我只能使用一个扩展程序,我在下面尝试了这个但是它不起作用

types = ('*.txt', '*.png')
files =glob.glob( os.path.join(path,types))

for f in files:
    part = MIMEBase('application', "octet-stream")
    part.set_payload( open(f,"rb").read() )
    Encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(f))
    msg.attach(part)

我收到以下错误

files =glob.glob( os.path.join(path,types))
  File "C:\Python27\lib\ntpath.py", line 73, in join
    elif isabs(b):
  File "C:\Python27\lib\ntpath.py", line 58, in isabs
    return s != '' and s[:1] in '/\\'
TypeError: 'in <string>' requires string as left operand, not tuple

0 个答案:

没有答案