Re: Dynamic/runtime code introspection/compilation
- From: Fredrik Lundh <fredrik@xxxxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 14:27:36 +0100
Thomas W wrote:
from somemodule import ISomeInteface
d = compile(sourcecode)
myfoo = d.Foo()
print ISomeInterface in myfoo.__bases__
Any hints?
Python is a dynamic language, so compiling something won't tell you much about what the code actually does. the only reliable way to do that is to execute the code:
code = compile(sourcecode)
namespace = {}
exec code in namespace
print issubclass(namespace["Foo"])
</F>
.
- References:
- Dynamic/runtime code introspection/compilation
- From: Thomas W
- Dynamic/runtime code introspection/compilation
- Prev by Date: Problem with imaplib (weird result if mailbox contains a %)
- Next by Date: Re: Dynamic/runtime code introspection/compilation
- Previous by thread: Dynamic/runtime code introspection/compilation
- Next by thread: Re: Dynamic/runtime code introspection/compilation
- Index(es):
Relevant Pages
|