Set a flag on the function or a global?

Oscar Benjamin oscar.j.benjamin at gmail.com
Tue Jun 16 08:45:01 EDT 2015


On 16 June 2015 at 09:18, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>
> 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.)

What's the point in giving edir two modes if one of them is the same
as dir? You could just do "from module import edir" and then use
dir/edir as desired.

Personally I just use ipython's tab-completion instead of dir. It
shows the dunders if you first type underscores but hides them
otherwise e.g.:

In [1]: a = []

In [2]: a.<tab>
a.append   a.count    a.extend   a.index    a.insert   a.pop
a.remove   a.reverse  a.sort

In [2]: a.__<tab>
a.__add__           a.__format__        a.__imul__          a.__new__
         a.__setslice__
a.__class__         a.__ge__            a.__init__
a.__reduce__        a.__sizeof__
a.__contains__      a.__getattribute__  a.__iter__
a.__reduce_ex__     a.__str__
a.__delattr__       a.__getitem__       a.__le__            a.__repr__
         a.__subclasshook__
a.__delitem__       a.__getslice__      a.__len__           a.__reversed__
a.__delslice__      a.__gt__            a.__lt__            a.__rmul__
a.__doc__           a.__hash__          a.__mul__           a.__setattr__
a.__eq__            a.__iadd__          a.__ne__            a.__setitem__


--
Oscar



More information about the Python-list mailing list