Printing literal text of an argument

Rex Eastbourne rex.eastbourne at gmail.com
Thu Aug 11 17:04:51 EDT 2005


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