David Bremner <[EMAIL PROTECTED]> writes: > At Wed, 18 Feb 2004 17:12:32 -0700, > Jason R Mastaler wrote: > >> Thanks, at least shell headers appear to work this time. >> >> > x-answer python="6*7" >> >> Did you try something other than manipulating integers? eval() doesn't >> seem to do what we need in this context -- even a simple 'print' >> statement doesn't work. >> > > Well, I was hoping that would be a feature :-). > > Basically it seems like in python you can have statements or > expressions, but not both. I'm not sure what one would want to > do with this python= tag. If we have little programlets then we > need to trap stdout and probably allow multiline quoted strings > (since for exec(), whitespace is significant). I > will investigate a little more.
Regardless of whether we use eval() or exec(), we will be limited to one line of Python code. The solution to having more than one line is to define a Python function in your config file. Once you've done that, eval() turns out to be simpler, since you can return a string containing anything that should be in the field body (i.e., whatever comes after "x-answer:" in the above example. If we use exec(), the return value is completely ignored. The function would have to print whatever it wanted the field value to be. The implementation in the filter would then create a StringIO object, save sys.stdout, set sys.stdout to the StringIO object, exec() the user's function (or code line), re-set sys.stdout to the real stdout and finally grab the actual string from the StringIO object. That's definitely doable, I'm up in the air about which would be easier to document and which would be easier for people to understand. Tim _________________________________________________ tmda-workers mailing list ([EMAIL PROTECTED]) http://tmda.net/lists/listinfo/tmda-workers
