def process_lines(fd, handler, cond=None):
    """
    Process all lines in fd

    if cond is not None, process only lines returning True for cond
    """

    if cond is not None:
        [ handler(line) for line in fd.readlines() if cond(line) ]
    else:
        [ handler(line) for line in fd.readlines() ]

    Process all lines in fd

    if cond is not None, process only lines returning True for cond
    
recipes/Python/414503_Generic_file_processor_method/recipe-414503.py