human
Complete this python program:
def generate_changelog(issues, after, heading, rtag=False):
assistant
#Here is the Python code you requested.

    """Prints out changelog.
    """
    relevent = relevant_issues(issues, after)
    relevent = sorted(relevent, key=ISSUES_BY_SECTION)
    def write(func, endofline='', append=''):
        func((((heading + '\n') + ('-' * 20)) + endofline))
        for (section, issue_group) in groupby(relevent, key=ISSUES_BY_SECTION):
            func(('        *    {}:'.format(section) + endofline))
            for issue in reversed(list(issue_group)):
                func(('                -    {}'.format(issue_line(issue)) + endofline))
        func((endofline + append))
    if (rtag is not False):
        with open('../CHANGELOG', 'r+') as f:
            content = f.read()
            f.seek(0)
            write(f.write, '\n', content)
    else:
        write(print)