<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def generate_py(module_name, code, optimizations=None, module_dir=None):
    '''python + pythran spec -> py code

    Prints and returns the optimized python code.

    '''

    pm, ir, _, _ = front_middle_end(module_name, code, optimizations,
                                    module_dir)

    return pm.dump(Python, ir)