(lines, regexp, new_line)
return updated_lines
Replace a line that matches 'regexp'
Replace a line that matches 'regexp'
Replace a line that matches regexp
def replace_line(lines, regexp, new_line):
    """
    Replace a line that matches 'regexp'
    """
    for (iline, line) in enumerate(lines):
        match_result = re.search(regexp, line)
        if match_result is not None:
            break
    updated_lines = lines[:]
    updated_lines[iline] = new_line
    return updated_lines
def replace_line ( lines , regexp , new_line ) : for ( iline , line ) in enumerate ( lines ) : match_result = re . search ( regexp , line ) if match_result is not None : break updated_lines = lines [ : ] updated_lines [ iline ] = new_line return updated_lines