simple string search and replace
Steve Holden
steve at holdenweb.com
Sat Mar 25 17:12:04 EST 2006
Kun wrote:
> hey guys, here's my code,
>
> senders = [('460 (BODY[HEADER.FIELDS (FROM)] {46}', 'From: Friend
> <anon at anon.wharton.com>\r\n\r\n'), ')', ('462 (BODY[HEADER.FIELDS
> (FROM)] {37}', 'From: Kun <neurogasm at gmail.com>\r\n\r\n'), ')']
> print senders
> parsed_senders = []
> sender = ""
> for item in senders:
> if isinstance(item,tuple):
> item= ''.join(item)
> if item==')':
> parsed_senders.append(sender[sender.find('<')+1:].strip())
> sender = ""
> else:
> sender+=item
> print parsed_senders
>
>
>
>
> wondering if anyone knows how i can remove the '>'s from the list, which
> outputs to something like ['anon at anon.wharton.com>', 'neurogasm at gmail.com>']
Where you append to parsed_senders, replace
sender[sender.find('<')+1:]
with
sender[sender.find('<')+1:-1]
and that will use a string one shorter, omitting the ">" character.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com
More information about the Python-list
mailing list