Sunday, 15 June 2014

algorithm - Can I apply a function to the variable in a for loop definition (Python) -


I am parsing email with Python 3.2.

I want to divide each email in a list file by email to a header list and a body list.

What do you think about this method?

  DEP DPAP (self): #head header body separates from #heads = []; Self.bodies = [] email.readlines () for self.inbox.dex: "" "The first 20 rows enclosed in the main list" "self.heads.append (email [: 10])" "" The remaining body list The line added in "self.bodies.append (Email [10:])   

self.inbox.dex is a list of files - Object

You were almost there

  ... Self.inbox for email. Dex: email = email.readlines () ...   

In addition, you can do this with an understanding of the list (more pack):

  Data = (email ([: 10], email [10:]) in email (x.readlines () self X inbox.dex) self.heads, self.bodies = zip (* data)    

No comments:

Post a Comment