Set a flag on the function or a global?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Jun 16 04:18:27 EDT 2015


On Tuesday 16 June 2015 10:35, MRAB wrote:

> On 2015-06-16 01:24, sohcahtoa82 at gmail.com wrote:

>> Using a keyword argument for the edir function is the most intuitive
>> and easy to read, IMO.

edir() has a keyword argument: edir(x, dunders=False) suppresses the return 
of dunder names. But since the primary purpose of [e]dir is, in my opinion, 
to be used interactively, needing to type an extra 15 characters to hide 
dunders is too inconvenient.


>> Also, if two people are working on the same script, it could create
>> problems if one person wants to filter them, but the other doesn't.
>> That would create a state that they would both have to monitor and
>> keep setting back and forth, rather than each one just setting an
>> argument on their calls.
>>
> But it's meant to be used interactively. If they're using it in a
> script, they'd most likely set the argument appropriately.

Yes.

The primary use-case (at least *my* use-case, and hopefully others) is to 
have "from module import edir as dir" in their Python startup file. That 
means that when running interactively, they will get the enhanced version of 
dir, but when running a script or an application they'll just get the 
regular one.

(Ideally, the regular one will eventually gain the same superpowers as edir 
has, but that's a discussion for another day.)

Besides, apart from the inspect module, which probably shouldn't, who uses 
dir() programmatically?

(If you do, you'll be glad to hear that edir() behaves the same as regular 
dir() by default.)


-- 
Steve




More information about the Python-list mailing list