[Tutor] introspection

Alex Kleider akleider at sonic.net
Fri May 8 08:26:43 CEST 2015


On 2015-05-07 20:45, Dave Angel wrote:

> You also only showed it working on module globals.  (For code at
> top-level, locals() returns the same as globals() )
> 
> You could also try it inside functions, where locals() really makes
> sense as a name.  And you could try it in a nested function where
> there may very well be non-locals (eg. closure items) that aren't
> local or global.

You've taken me to new territory:
http://www.shutupandship.com/2012/01/python-closures-explained.html
I wasn't familiar with 'closures' and to be truthful, still am not,
although thanks to you I am at least aware of the idea.
> 
> But more interestingly, you could try it on items of a list, or
> members of a dictionary, where there's no name at all associated with
> the object.

It simply returns None.  I assume that's the point you are making?
(That it has no name, or perhaps more accurately expressed: there is
no name to discover.)

alex



More information about the Tutor mailing list