python pop3 收邮件
def retrive_emails(pop3_server, user_name, passwd, server_port):
#POP3
pop_client = poplib.POP3(pop3_server, port=server_port)
pop_client.user(user_name)
pop_client.pass_(passwd)
#print messages num
num_messages, mbox_size = pop_client.stat()
print 'there are %s new emails\n' % num_messages
if num_messages == 0:
pop_client.quit()
return
print('num of messages %s' %str(num_messages))
#mk folder
folder_name = '%s-%s' %(user_name, pop3_server)
if not os.path.exists(folder_name):
os.mkdir(folder_name)
for idx in range(num_messages):
one_mail = pop_client.retr(idx+1)
buf = cStringIO.StringIO()
for j in one_mail[1]:
print >>buf,j
buf.seek(0)
#parse mail content
msg = email.message_from_file(buf)
for part in msg.walk():
contenttype = part.get_content_type()
print('\npart:\n%s\n' % part)
&
相关文档:
Python http://www.python.org/download/ wxPython http://www.wxpython.org/download.php#binaries Vpython http://vpython.org/contents/download_windows.html Matplotlib http://sourceforge.net/projects/matplotlib/files/matplotlib/ PyGlet http://www.pyglet.org/download.html PyGame http://www.pyga ......
#将一些类型的文件压缩为7z.py
#for folder all file do 7z
import os
import sys
import distutils.file_util
def ImportOkFile():
if(os.path.isfile("D:\\Records\\将一些类型的文件压缩为7z_record.txt")==False):
f=open("D:\\Reco ......
Ruby和Python的语法比较
其实Ruby和Python非常接近,比大多数别的语言要接近的多,所以喜欢用啥就用啥(大实话,虽然也是废话)。语法上的差别虽然有那么一点,大部分是syntax sugar,我斗胆稍微列几个(python我也忘得差不多了,不对的大家尽管来鞭尸吧),但是主要差异还是设计思想上的:灵活 ......
conn = httplib.HTTPConnection(EPG_IP + ":" + HTTP_PORT)
url = FAV_URL_PARTH +"userid=" + USER_ID + FAV_DIR_MODIFY
param = '''<ps100request id="Favorite.Category.modify">
<categoryid>'''+categoryid+'''</categoryid>
<categoryname>'''+categoryname+'''</ ......
Python 的异常处理机制
Python代码
try:
raise Exception("a", "b")
except Exception,e:
print e
finally:
print "final"
('a', ......