Use list name as string

Tino Wildenhain tino at
Thu Feb 5 10:39:24 CET 2009

Hendrik van Rooyen wrote:
 >  "MRAB" <google at> wrote:
 >> The actual names of the variables and functions shouldn't matter to the
 >> outside world; the name of an output file shouldn't depend on the name
 >> of a variable.
 > That is a matter of opinion.
 > It is however, an interesting problem, namely:
 > How does one get hold of the actual name by which some parameter
 > is passed?
 > you may want to print, as a debug thingy:
 > print "the name passed in was: ", ImpossibleThingYieldingName
 > print "and it evaluates to:" , ArgumentPassed

This is possible to some degree:

import inspect

def F(a):
         print "F(%s) called from '%s' within '%s' line %d" %
         for ln,srcline in enumerate(contextlines or []):
             print "%3s : %s" % ('*>' if ln==contextindex else '',srcline)

just play around calling the above function from different
places and you should see what I mean :-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
URL: <>

More information about the Python-list mailing list