Printing literal text of an argument

Jeremy Moles jeremy at emperorlinux.com
Thu Aug 11 18:46:02 EDT 2005


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:
> 
> 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 thing twice (one in quotes and the other not)
> sets off an alarm in my head. Is there a way to make this function take
> only one argument, and use both its value and its literal form? On a
> slightly different topic, is it also possible to make the macro print
> the line number where the function was first called?
> 
> Thanks,
> 
> Rex
> 




More information about the Python-list mailing list