On 5/1/07, Dotan Cohen <[EMAIL PROTECTED]> wrote:
I have had the misfortune of having a university Windows machine
garble all the email addresses in my addressbook (a txt file so that I
can use it both on my home Fedora machine and on the university
Windows machines). I figure this is as good a time as any to start
learning python and fix the file. How can I iteriate through a text
file that looks like this:

 "=?UTF-8?B?157XqNeZ15Qg15nXoNeY16bXnw==?=" <[EMAIL PROTECTED]>,
 "=?UTF-8?B?157XqNenINen15nXmNek15XXkQ==?=" <[EMAIL PROTECTED]>,
 "=?UTF-8?B?157XqdeUINem15LXkNeZ?=" <[EMAIL PROTECTED]>,

and have it return:
[EMAIL PROTECTED],
[EMAIL PROTECTED],
[EMAIL PROTECTED],

Thanks in advance.

Dotan Cohen

http://lyricslist.com/
http://what-is-what.com/
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Hi Dotan!  Welcome to python!

Here is some code that will do what you need.  It uses the re module,
which are regular expressions.

# You need to import the module:
import re

# Then you need to read in the file that contains your list.
email_list = open("brokenemails.txt","r")

# We need to generate your regular expression.  The grabs anything in
# the file that is between < and >, but it includes the <>
re_mail=re.compile(r"\<(.*)\>")

# Then filter each line of the file through the regex, discarding the
# <> from above, and puts each address into a list.
addresses = [re_mail.search(line).group(1) for line in
email_list.readlines()]

# Now we print them out, comma and newline separated
print ",\n".join(addresses)

Let me know if you need more detail!

Your pal,
Ben
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to