def compile_and_load(code): r""" INPUT: - ``code`` -- string containing code that could be in a .pyx file that is attached or put in a %cython block in the notebook. OUTPUT: a module, which results from compiling the given code and importing it EXAMPLES:: sage: module = sage.misc.cython.compile_and_load("def f(int n):\n return n*n") sage: module.f(10) 100 """ from sage.misc.temporary_file import tmp_filename file = tmp_filename(ext=".pyx") open(file,'w').write(code) from sage.server.support import cython_import return cython_import(file, create_local_c_file=False)
def compile_and_load(code): r""" INPUT: - ``code`` -- string containing code that could be in a .pyx file that is attached or put in a %cython block in the notebook. OUTPUT: a module, which results from compiling the given code and importing it EXAMPLES:: sage: module = sage.misc.cython.compile_and_load("def f(int n):\n return n*n") sage: module.f(10) 100 """ from sage.misc.temporary_file import tmp_filename file = tmp_filename(ext=".pyx") open(file, 'w').write(code) from sage.server.support import cython_import return cython_import(file, create_local_c_file=False)