我正在使用imaplib进行Gmail访问,并遇到:
# Count the unread emails
status, response = imap_server.status('INBOX', "(UNSEEN)")
unreadcount = int(response[0].split()[2].strip(').,]'))
print unreadcount
Run Code Online (Sandbox Code Playgroud)
我只想知道:
status,
Run Code Online (Sandbox Code Playgroud)
在"response ="之前做.我会谷歌它,但我不知道我甚至要求找到答案:(.
谢谢.
cwa*_*ole 13
当函数返回一个元组时,它可以由多个变量读取.
def ret_tup():
return 1,2 # can also be written with parens
a,b = ret_tup()
Run Code Online (Sandbox Code Playgroud)
a和b分别为1和2
请参阅此页面:http: //docs.python.org/tutorial/datastructures.html
第5.3节提到"多重赋值"又称"序列解包"
基本上,函数imap_server返回一个元组,而python允许一个快捷方式,允许您为元组的每个成员初始化变量.你可以轻松完成
tuple = imap_server.status('INBOX', "(UNSEEN)")
status = tuple[0]
response = tuple[1]
Run Code Online (Sandbox Code Playgroud)
所以最后,只是一个句法快捷方式.您可以使用任务右侧的任何类似序列的对象执行此操作.