Python:如何将终端中打印的内容保存为变量以供以后比较?
import imaplib
import pprint
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
rc, resp = M.login('[email protected]', 'password')
print rc, resp
M.select()
for msg_num in M.search(None, "UNDELETED")[1][0].split():
msg = M.fetch('1', '(BODY.PEEK[TEXT])')
print msg[1][0][1][139:161]
M.close()
M.logout()
我是 python 编程的新手,上面的 python 代码是我用于我想做的程序的代码。当我在终端中运行此命令时,我得到的响应是我已经验证了我的帐户,然后它显示字符 139 和 139 之间的消息。 161,在示例电子邮件中如下:
这只是一个测试...
这在终端中打印出来。我想做的就是将此打印输出与其他内容进行比较。例如:如果a=b则x。我想做的是,如果语句为真则向串口发送信号。
感谢所有帮助,我们感谢并期待任何帮助......
import imaplib
import pprint
IMAP_SERVER='imap.gmail.com'
IMAP_PORT=993
M = imaplib.IMAP4_SSL(IMAP_SERVER, IMAP_PORT)
rc, resp = M.login('[email protected]', 'password')
print rc, resp
M.select()
for msg_num in M.search(None, "UNDELETED")[1][0].split():
msg = M.fetch('1', '(BODY.PEEK[TEXT])')
print msg[1][0][1][139:161]
M.close()
M.logout()
I'm a new beginner in python programming and the above python code is one that I'm using for a program I want to do. When I run this in a terminal I get the response that I have authenticated my account and then it displays the message between characters 139 & 161, which is the following in the example email:
This is just a test...
This is printed out in the terminal. What I want to do is take this printout and compare it to something else. For example: if a=b then x. What I want to do is that if the statement is true to send a signal to the serial port.
Any help is appreciated and anticipated thanks to all that help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需在打印之前将消息分配给一个变量即可:
显然,您应该使用比“
a
”更有意义的变量名称。Simply assign the message to a variable before you print it:
Obviously, you should use a more meaningful variable name than "
a
".