Hello! I copy and paste this code [ref1] to the default controller of the default application:
def testImportCode(): # Example code = \ """ def testFunc(): return "spam!" class testClass: def testMethod(self): return "eggs!" """ m = importCode(code,"test") spam = m.testFunc() o = m.testClass() eggs = o.testMethod() cont = DIV(P(m), P(spam), P(o), P(eggs)) return cont def importCode(code,name,add_to_sys_modules=0): """ Import dynamically generated code as a module. code is the object containing the code (a string, a file handle or an actual compiled code object, same types as accepted by an exec statement). The name is the name to give to the module, and the final argument says wheter to add it to sys.modules or not. If it is added, a subsequent import statement using name will return this module. If it is not added to sys.modules import will try to load it in the normal fashion. import foo is equivalent to foofile = open("/path/to/foo.py") foo = importCode(foofile,"foo",1) Returns a newly generated module. """ import sys import imp module = imp.new_module(name) exec code in module.__dict__ if add_to_sys_modules: sys.modules[name] = module return module Question N1 - How can i save and get the #example code from database? Question N2 - Why the page .../admin/default/design/application is now exposing testFunc():? # Example code = \ """ def testFunc(): return "spam!" class testClass: def testMethod(self): return "eggs!" """ ref1 - http://code.activestate.com/recipes/82234-importing-a-dynamically-generated-module/ Can someone switch on the light.PLEASE.