I'm fairly new to python and confused with nesting a if
function within a for loop
I only want the for loop
to continue based on the return value from the if
.
In this case, I'm looking to iterate over all Message`s in an inbox, if their read value is False iterate over the attachments of Messages that are not read..
However, using the below I keep getting all attachments saved regardless of their read value being True
or 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)
have I completly written this wrong? or are my indents incorrect?
Update
Using
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)
The print statement returns True
& False
value
thanks
Not entirely sure why but making two changes it is now working.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.