Compiling Python code within a module

Mitko Haralanov mitko at qlogic.com
Fri May 18 19:49:33 EDT 2007


On 18 May 2007 15:51:40 -0700
ici <iltchevi at gmail.com> wrote:

> exec it :)

Thank you! That works when I compile/exec it in the main body of the
program. However, when I try to do that in a separate module it
doesn't. For example:

Module Foo:
import compiler

class Foo:
	def __init__ (self):
		return
	def register (self, text):
		exec (compiler.compile (text, "<string>",
						"exec"))

File Bar:
import Foo

f = Foo.Foo ()
f.register ("def blah():\n\tprint 'blah'\n")

In this case, the function 'blah' is nowhere to be found. I've tried
looking in 'f', in the class 'Foo', in the module 'Foo' and it's
nowhere.

-- 
Mitko Haralanov					 mitko at qlogic.com
Senior Software Engineer			     650.934.8064
System Interconnect Group		    http://www.qlogic.com

==========================================
((lambda (foo) (bar foo)) (baz))



More information about the Python-list mailing list