如何使用imaplib从单个邮件下载多个附件?
假设我有一封电子邮件,该电子邮件包含4个附件.如何下载所有这些附件?以下代码仅从电子邮件中下载单个附件.
detach_dir = 'c:/downloads'
m = imaplib.IMAP4_SSL("imap.gmail.com")
m.login('hello@gmail.com','3323434')
m.select("[Gmail]/All Mail")
resp, items = m.search(None, "(UNSEEN)")
items = items[0].split()
for emailid in items:
resp, data = m.fetch(emailid, "(RFC822)")
email_body = data[0][1]
mail = email.message_from_string(email_body)
temp = m.store(emailid,'+FLAGS', '\\Seen')
m.expunge()
if mail.get_content_maintype() != 'multipart':
continue
print "["+mail["From"]+"] :" + mail["Subject"]
for part in mail.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
filename = part.get_filename()
att_path = os.path.join(detach_dir, filename)
if not os.path.isfile(att_path) :
fp = open(att_path, 'wb') …Run Code Online (Sandbox Code Playgroud) 我无法想象在pygame中显示文本.
我知道我不能像常规python IDLE一样使用print但我不知道怎么做
import pygame, sys
from pygame.locals import *
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = ( 255, 0, 0)
pygame.init()
size = (700, 500)
screen = pygame.display.set_mode(size)
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('P.Earth')
while 1: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.display.update()
import time
direction = ''
print('Welcome to Earth')
pygame.draw.rect(screen, RED, [55,500,10,5], 0)
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
这只是整个计划的开始部分.
如果有一种格式允许我显示我在pygame窗口中键入的文本,那就太棒了.因此,不使用打印,我会使用其他东西.但我不知道那是什么东西:/当我在pygame中运行我的程序时,它没有显示任何东西.
我希望程序在pygame窗口中运行,而不是只在空闲时运行.
我有两个列表,x和y.
x包含字母AZ和Y包含它们在文件中的频率.
我已经尝试过研究如何在直方图中绘制这些值,但是在理解如何绘制它时没有成功.
n, bins, patches = plt.hist(x, 26, normed=1, facecolor='blue', alpha=0.75)
Run Code Online (Sandbox Code Playgroud)
x是上面列表中的列表x吗?
Seaborn提供了一些非常有趣的科学数据表示图形.因此,我开始使用这些Seaborn图形穿插其他定制的matplotlib图.问题是,一旦我这样做:
import seaborn as sb
Run Code Online (Sandbox Code Playgroud)
这个导入似乎设置了seaborn全局的图形参数,然后导入下面的所有matplotlib图形都获得了seaborn参数(它们得到灰色背景,linewithd更改等等).
在SO中有一个答案解释如何使用matplotlib配置生成seaborn图,但我想要的是在将两个库一起使用时保持matplotlib配置参数不变,同时能够在需要时生成原始的seaborn图.
我使用Qt4 Designer,我希望当我点击"是"按钮时,会执行一些代码.当我点击"否"时,其他一些代码将被执行.我该怎么做?
我在Python 2.6和3.2中遇到了令我惊讶的行为:
>>> xs = dict.fromkeys(range(2), [])
>>> xs
{0: [], 1: []}
>>> xs[0].append(1)
>>> xs
{0: [1], 1: [1]}
Run Code Online (Sandbox Code Playgroud)
然而,dict3.2中的理解表现出更礼貌的举止:
>>> xs = {i:[] for i in range(2)}
>>> xs
{0: [], 1: []}
>>> xs[0].append(1)
>>> xs
{0: [1], 1: []}
>>>
Run Code Online (Sandbox Code Playgroud)
为什么fromkeys这样做?
我有一些代码来绘制点:
import matplotlib.pyplot as plot
from matplotlib import pyplot
all_data = [[1,10],[2,10],[3,10],[4,10],[5,10],[3,1],[3,2],[3,3],[3,4],[3,5]]
x = []
y = []
for i in xrange(len(all_data)):
x.append(all_data[i][0])
y.append(all_data[i][1])
plot.scatter(x,y)
pyplot.show()
Run Code Online (Sandbox Code Playgroud)
但我希望所有可能的行看起来像这样:

我尝试过matplotlib路径,但它对我来说效果不佳.
我在计算机A上安装了Oracle 11g XE.我可以使用该命令通过sql命令行连接connect username/password.我也可以将SQL指令发送到Demo数据库:Select * from demo_customers;
数据库在计算机A的localhost上运行.
我希望计算机B连接到localhost上的计算机A的数据库.我怎样才能做到这一点?
我对标识符有以下定义:
Identifier --> letter{ letter| digit}
Run Code Online (Sandbox Code Playgroud)
基本上我有一个标识符函数,它从文件中获取一个字符串并对其进行测试,以确保它是上面定义的有效标识符.
我试过这个:
if re.match('\w+(\w\d)?', i):
return True
else:
return False
Run Code Online (Sandbox Code Playgroud)
但是当我每次遇到一个整数运行我的程序时,它认为它是一个有效的标识符.
例如
c = 0 ;
Run Code Online (Sandbox Code Playgroud)
它打印c为有效的标识符,很好,但它也打印0为有效的标识符.
我在这做错了什么?
我尝试使用pyparsing来解析这些逻辑表达式
x
FALSE
NOT x
(x + y <= 5) AND (y >= 10) OR NOT (z < 100 OR w)
(A=True OR NOT (G < 8) => S = J) => ((P = A) AND not (P = 1) AND (B = O)) => (S = T)
((P = T) AND NOT (K =J) AND (B = F)) => (S = O) AND
((P = T) OR (k and b => (8 + z <= 10)) AND NOT (a …Run Code Online (Sandbox Code Playgroud) python ×9
matplotlib ×2
attachment ×1
email ×1
for-loop ×1
frequency ×1
histogram ×1
identifier ×1
imap ×1
oracle ×1
oracle11g ×1
pygame ×1
pyparsing ×1
qt-designer ×1
qt4 ×1
regex ×1
seaborn ×1
text ×1