Re: Printing literal text of an argument

2005-08-13 Thread Paul McGuire
Rex - If what you are looking for is a monitor of calls to a certain function, check out this decorator example from the Python Wiki: http://wiki.python.org/moin/PythonDecoratorLibrary?highlight=%28Decorator%29#head-d4ce77c6d6e75aad25baf982f6fec0ff4b3653f4 This will allow you to very quickly tur

Re: Printing literal text of an argument

2005-08-13 Thread Reinhold Birkenfeld
Rex Eastbourne wrote: > Thanks. I adapted it a bit: > > def debug(foo): > print foo, 'is:' > exec('pprint.pprint(' + foo + ')') > > But I'm getting "NameError: name 'foo' is not defined," since foo is > not defined in this scope. (The function works beautifully when I'm > dealing with glo

Re: Printing literal text of an argument

2005-08-11 Thread Rex Eastbourne
Thanks. I adapted it a bit: def debug(foo): print foo, 'is:' exec('pprint.pprint(' + foo + ')') But I'm getting "NameError: name 'foo' is not defined," since foo is not defined in this scope. (The function works beautifully when I'm dealing with global variables, which is very rarely). A

Re: Printing literal text of an argument

2005-08-11 Thread Gregory Bond
Rex Eastbourne wrote: > def debug(aname, avalue): > print aname, 'is': > pprint.pprint(avalue) > use eval: def debug(s): print s, 'is' pprint.pprint(eval(s)) (it does mean the arg is a string not code..) > On a > slightly different topic, is it also possible to ma

Re: Printing literal text of an argument

2005-08-11 Thread Mike Meyer
[Format recovered from top posting] Jeremy Moles <[EMAIL PROTECTED]> writes: > On Thu, 2005-08-11 at 14:04 -0700, Rex Eastbourne wrote: >> Hi all, >> >> I've written the following simple macro called debug(aname, avalue) >> that prints out the name of an expression and its value: >> >> def debug

Re: Printing literal text of an argument

2005-08-11 Thread Jeremy Moles
def debug(s): print "s" exec(s) The line thing i'm not so sure about. Er. Hmmm. On Thu, 2005-08-11 at 14:04 -0700, Rex Eastbourne wrote: > Hi all, > > I've written the following simple macro called debug(aname, avalue) > that prints out the name of an expression and its value: >

Printing literal text of an argument

2005-08-11 Thread Rex Eastbourne
Hi all, I've written the following simple macro called debug(aname, avalue) that prints out the name of an expression and its value: def debug(aname, avalue): print aname, 'is': pprint.pprint(avalue) An example call is: debug('compose(f1,f2)', compose(f1,f2)) Writing the exact same thi