我对python还是很陌生,并且在if
内嵌套for loop
函数感到困惑
我只希望for loop
根据if
的返回值继续。
在这种情况下,我要遍历收件箱中的所有Message,如果它们的读取值为False,则遍历未读取的邮件附件。
但是,无论使用什么读取值,True
或False
,我都会使用以下内容保存所有附件
for Message in mail_folders.get_messages():
if Message.is_read == False:
for att in Message.attachments:
if '.html' in att.name:
att.save(sv_path)
我完全写错了吗?还是我的缩进不正确?
更新
使用
for Message in mail_folders.get_messages():
print(Message.is_read)
if Message.is_read == False:
for att in Message.attachments:
if '.html' in att.name:
att.save(sv_path)
print语句返回True
和False
值
谢谢
答案 0 :(得分:0)
不能完全确定为什么,但是进行两项更改现在可以正常工作。
for m in mail_folders.get_messages(download_attachments = True):
print(m.is_read)
if m.is_read == False:
for att in m.attachments:
if '.html' in att.name:
att.save(sv_path)