การสร้างฟังก์ชันไดนามิกโดยใช้ globals() ใน python

import pytest 
import input_csv

datalist = input_csv.csvdata()


def display():
    return 10 + 5


for data in datalist:
    functionname = data['TCID']
    parameters = [data['Template_name'], data['File_Type']]
    body = 'print(display())'


    def createfunc(name, *params, code):
        exec('''
@pytest.mark.regression
def {}({}):
    {}'''.format(name, ', '.join(params), code), globals(), globals())


    createfunc(functionname, data['Template_name'], data['File_Type'], code=body)
    templateName = data['Template_name']
    fileType = data['File_Type']
    globals()[functionname](templateName, fileType)