thanks matthew. i'll take a look at that.

-chad

On Tue, Sep 30, 2008 at 2:19 PM, Matthew Chapman <[EMAIL PROTECTED]>wrote:

> I think you could use
> http://docs.python.org/lib/module-code.html
>
> I found 'sys.settrace()' useful for debugging and logging.
> http://docs.python.org/lib/debugger-hooks.html#debugger-hooks
> http://docs.python.org/lib/inspect-types.html
>
> import sys
>
> def anotherCall():
>     "Does Not Save"
>     return "Func Return"
>
> def getVersion(default='Default Arg'):
>     assignA = ' Assign Func Block'
>     assignB = anotherCall()
>     return sys.version
>
> def probeFunc(frame, event, arg):
>     print '\nFrame Name:',frame.f_code.co_name, "\nEvent:", event,
> "\nArgument:", arg
>     for each in  frame.f_locals:
>         print "f_locals:", each, ">", frame.f_locals[each]
>     return probeFunc
>
> sys.settrace(probeFunc)
> getVersion()
> sys.settrace(None)
>
>
>
>
> On Mon, Sep 29, 2008 at 10:23 PM, Chadrik <[EMAIL PROTECTED]> wrote:
>
>>
>>
>> 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.
-~----------~----~----~----~------~----~------~--~---

Reply via email to