[Python-Dev] nonlocals() function?
Carl M. Johnson
cmjohnson.mailinglist at gmail.com
Mon Apr 5 05:21:44 CEST 2010
On Sun, Apr 4, 2010 at 1:44 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> On Mon, 5 Apr 2010 09:03:17 am average wrote:
>> presently). That includes dir() too and probably others.
>
> You are confused -- globals() and locals() don't return lists.
Yeah, this thread is mostly a mess (what would nonlocals() return
anyway?), but there is one serious suggestion in there. Maybe dir()
should return a set.
Points in its favor:
* The results of dir() are non-repeating
* The order of items returned by dir() is not especially important
* It would make "method" in dir(obj) marginally faster
Points against:
* It would break code that tried dir(obj)[0] (but why would anyone do that?)
* Even though the order isn’t important for code, it’s convenient at
the interactive prompt to see the methods of an item in alphabetical
order for quick scanning.
Overall:
-0
My two bits.
-- Carl Johnson
More information about the Python-Dev
mailing list