def _update(line_replacement): limits_list = limits_conf.readlines() newlines = [] for item in limits_list: line_memlock = find_memlock.search(item) #Is the current line the one we want? if line_memlock: print 'found the line' newlines.append(find_memlock.sub(line_replacement, item)) else: print 'this is not the line' newlines.append(item) print newlines limits_conf.seek(0) limits_conf.writelines(newlines)