What is the most Pythonic way to modify the function of a function?
Question: I have a function I am using to read in files of a particular format. My
function looks likes this:

    
    
    import csv
    from collections import namedtuple
    
    def read_file(f, name, header=True):
        with open(f, mode="r") as infile:
            reader = csv.reader(infile, delimiter="\t")
            if header is True:
                next(reader)
            gene_data = namedtuple("Data", 'id, name, q, start, end, sym')
            for row in reader:
                row = data(*row)
                yield row
    

I also have another type of file that I would like to read in with this
function. However, the other file type needs a few slight parsing steps before
I can use the `read_file` function. For example, trailing periods need to be
striped from column `q` and the characters `atr` need to be appended to the
`id` column. Obviously, I could create a new function, or add some optional
arguments to the existing function, but is there a simple way to modify this
function so that it can be used to read in an additional file type(s)? I was
thinking of something along the lines of a decorator?


Answer: IMHO, the most Pythonic way would be converting the function to a base class,
split file operations into methods and overriding these methods in new classes
based on your base class.

