本质上,我想做一个临时的超级字数统计,但我不确定如何从目录路径(作为参数传入)创建一个 dict 对象,而不是一个列表来做我需要做的事情。
虽然我想创建一个字典对象,但我还想使用电子邮件模块将作为文件名的键的 ASCII 值格式化为电子邮件或消息对象。然后我想使用有效负载提取正文并以这种方式解析它。我在下面有一些例子:
mylist=os.listdir(sys.stdin)
for emails in mylist:
email_str = emails.open()
#uncertain if this will get all emails and their content or not
#all emails are supposed to have a unique identifier, they are essentially still just ascii
file_dict = {emails : email_str}
#file_dict = dict(zip(mylist, mylist))
for emails in file_dict[emails]:
msg = email.message_from_string(email_str)
body = msg.get_payload(decode=True)
#I'm not entirely sure how message objects and sub objects work, but I want the header to
#signature and I'm not sure about the type of emails as far as header style
#pretend I have a parsing method here that implements the word count and prints it as a dict:
body.parse(regex)
除了解析它们的值之外,我并不完全需要这些键,因此我可以考虑使用 message_from_file 代替。