Now it works: rex = re.compile(r'(^.*username *=[^"]*")([^"]*)(".*$)') for line in fileinput.input(FILE, inplace=1): m = rex.match(line) if m is not None: line = "%s%s%s\n" % (m.group(1), new_name, m.group(3)) print line
But there is an extra line break after each line in FILE. Why is that? I tried to line = "%s%s%s" % (m.group(1), new_name, m.group(3)) but it turns out there are two extra line breaks after each line... -- http://mail.python.org/mailman/listinfo/python-list