[Tutor] Where did those spaces come from?
Tom Tucker
tktucker at gmail.com
Tue Sep 13 03:37:54 CEST 2005
Tutor,
Good evening! The goal is to parse a simple file and grab column one.
Then print each value horizontally separated by a comma.
Why is Python adding a space padding between each value? Please see below.
Thanks ahead of time.
INPUT_FILE # unwanted lines removed
################################
5555 user at bdomain.com blah blah
1111 user at cdomain.com blah blah
3333 user at adomain.com blah blah
4444 user at edomain.com blah blah
OUTPUT DESIRED
##################
5555,1111,3333,4444
SCRIPT
#########
import re
input_file = open('/tmp/file','r')
number_match = re.compile('^\d+\s+\w+\@')
for line in input_file.readlines():
if number_match.match(line):
line = re.split('\s+', line)
print line[0],
print ",",
OUTPUT GENERATED
####################
5555 , 1111 , 3333 , 4444 ,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050912/844cae81/attachment.html
More information about the Tutor
mailing list