def _try_compile ( source , name ) : try : c = compile ( source , name , 'eval' ) except SyntaxError : c = compile ( source , name , 'exec' ) return c
python compile string function
Attempts to compile the given source first as an expression and then as a statement if the first approach fails .
def _try_compile(source, name):
    """Attempts to compile the given source, first as an expression and
       then as a statement if the first approach fails.

       Utility function to accept strings in functions that otherwise
       expect code objects
    """
    try:
        c = compile(source, name, 'eval')
    except SyntaxError:
        c = compile(source, name, 'exec')
    return c