[Tutor] Converting code to string

Alan Gauld alan.gauld at btinternet.com
Fri Aug 24 00:04:48 CEST 2007

"Bernard Lebel" <3dbernard at gmail.com> wrote

> Why? Because I'm using an API (the Softimage|XSI scripting API) 
> where
> I have to create a custom GUI (using that API's GUI toolkit).
> I have to attach a logic callback to a number of widgets that can
> change from one execution to the next.

Can you show us a simple(!) example, I'm not sure I quite understand
the parameters of the problem.

How does the XSI GUI execute the code you pass to it?
If it executes it by itself then it why not just write the callbacks
as strings:

## create a foo wrapper
def foo(x):

def myfoo(x):
    real code here

Or do you need to call them too?

This might be a valid use for exec:

foostr = '''
def foo(x);
   print x

> The only way to do that, in that API, is to define the callback
> functions "on-the-fly".

But I'm not sure what the restrictions of 'on the fly' are. How
close to runtime must the definition be? Could it be
parameterised by a format string?

> And to define such a callback, the API
> requires that the function must be represented as a string.

How bizarre!


Alan G. 

More information about the Tutor mailing list