hi all, this is not maya related, but since you all are the most knowledgeable python people i know, i thought i'd give it a go:
i'm trying to write something that can execute python code line-by- line like a terminal, and capture up the output. the problem is that eval only works on expressions and exec does not return results. for instance, lets say i wanted to run this code: >>> import sys >>> sys.version the result i should capture for the second line would be: '2.5.1 (r251:54869, Apr 18 2007, 22:08:04) \n[GCC 4.0.1 (Apple Computer, Inc. build 5367)]' i tried redirecting sys.stdout to a file, but it only captures printed statements. right now i have something sort of working which first attempts to use eval, then if that fails, it uses exec. ( i also have something to handle more complicated structures like if/elif/else, which it detects and accumulates into a longer string for the exec statement ). anyway, this eval/exec combo felt kind of hacky and i thought there might be a more straightforward way of doing this. playing with ipython really opened my eyes because of how deeply it modifies the interpreter, all done in pure python. i still don't really understand what is going on behind the scenes when i enter a line of text into the python interpreter. is it running exec in the background or is there some deeper magic? -chad --~--~---------~--~----~------------~-------~--~----~ Yours, Maya-Python Club Team. -~----------~----~----~----~------~----~------~--~---
