[Tutor] inquire

D-Man dsh8290@rit.edu
Thu, 11 Jan 2001 13:54:13 -0500


On Thu, Jan 11, 2001 at 01:19:56PM -0500, Michael P. Reilly wrote:
| > Dear Sir/Madam,
| > 
| > Does python offer any method or function to return the name of any object?
| > eg.
| > 
| > >>>aaa=None
| > >>>print Wanted_Function(aaa)
| > 'aaa'
| > 
| > the question is if such a function like Wanted_Function() actually exists.
| > 
| > Many Thanks,
| > Xia XQ
| 
| Not easily, no.  As D-Man was referring to, Python is not a variable-
| based language, but a name-binding one (that is why there is no pointer
| dereferencing).
[snip]

On the other hand, some objects do have a __name__ attribute, but not
variables.  Those objects include modules, functions and classes.

Try this:

>>> import os
>>> os.__name__
'os'
>>> foo = os
>>> foo.__name__
'os'

:-)

Not quite what you were looking for, right?

-D