How do I create a dynamic wrapper for another language?
Whitney Battestilli
whitney at battestilli.net
Fri May 21 12:30:28 EDT 2004
Has,
Thanks! This is exactly what I was missing.
I appreciate everybody's suggestions and the loads of general good info
on this list. I'm going to be able to get back into python for a few
months ( after a few year break ). I'll try to lurk on the list and
pitch in.
Thanks again,
--Whitney.
On Fri, 2004-05-21 at 10:33, has wrote:
> > Whitney Battestilli wrote:
> >
> > > I'm trying to embed python into an application that already contains a
> > > scripting language. This scripting language contains thousands of
> > > commands and I have the ability to query the script engine and get
> > > syntax information regarding valid arguments and such.
> > >
> > > Rather than writing explicate wrappers for each command (which will be
> > > very time consuming), I would like to extend python by creating a module
> > > that allows any function name to be executed with any number of keyword
> > > arguments.. I would then like to take the function name and keyword
> > > arguments and pass these to the apps script engine in the format required.
> > >
> > > Is there any way to do this or any way to do something like this?
>
> It's pretty easy using Python's introspection features to supply the
> syntactic sugar. Simple example:
>
> class _Callable:
> def __init__(self, name):
> self._name = name
>
> def __call__(self, **args):
> # [Do argument name checking, etc. here]
> # [Dispatch command here]
> print 'Sending command %r with arguments: %r' % (self._name,
> args) # TEST
>
> class Bridge:
> def __getattr__(self, name):
> # [Do command name checking here]
> return _Callable(name)
>
>
> bridge = Bridge()
> bridge.foo(bar=1, baz=True) # -> Sending command 'foo' with arguments
> {'baz': True, 'bar': 1}
>
>
> Also see my Python-to-Apple Event Manager bridge for ideas and/or
> code: http://freespace.virgin.net/hamish.sanderson/appscript.html
Whitney Battestilli
Cell: 919-949-0686
OpenPGP Public Key
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20040521/2b8a718e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 196 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/python-list/attachments/20040521/2b8a718e/attachment.sig>
More information about the Python-list
mailing list