Exposing object model in Python?
Fredrik Lundh
fredrik at pythonware.com
Fri Jun 27 09:53:12 EDT 2003
Steve Holden wrote:
> > I'm writing a classical desktop application, using wxPython
> > and some other libraries. I'm interested to expose its
> > object model a la Microsoft's VBA. That is, I want to allow
> > my users to tinker with the app, i.e. write their own macros
> > in Python in a miniature IDE, within the app. I'd also like to ship
> > the program as a standalone app, using py2exe.
> Unfortunately the techniques used are a little too complicated to describe
> in a newsgroup posting.
>
> with-apologies-to-pierre-de-fermat-ly y'rs - steve
macrosource = getmacro(macroname)
code = compile(macrosource, macroname, "exec")
context = {}
# populate context with fun things
context["app"] = object_representing_my_app
exec code in context
(add exception handling as necessary)
</F>
More information about the Python-list
mailing list