python parse file
file, io, parsing, python, save
Solution
import sys
infile, outfile = sys.argv[1], sys.argv[2]
with open(infile) as inf, open(outfile,"w") as outf:
line_words = (line.split(',') for line in inf)
outf.writelines(words[1].strip() + '\n' for words in line_words if len(words)>1)
Problem
I have a file with username and emails, in this format : ``` pete,pbellyer@gmail.com ``` I want to only keep the email, so i thought about using a regex like this : ``` import re,sys Mailfile = sys.argv[1] file = open(Mailfile, "r") for MAIL in file.readlines(): tmp = re.split("\n+", MAIL) m = re.match( ',(.+)', MAIL) m.group(0) ``` But then I don't know how to store the result in a file. I always get the last email address in the new file. What would be the best way to store the results in a file ? Thanks!