Set a flag on the function or a global?

Steven D'Aprano steve at pearwood.info
Wed Jun 17 11:55:36 EDT 2015


On Thu, 18 Jun 2015 01:06 am, Laura Creighton wrote:

> To figure out what I like, I would need to play with edir, and the
> suite that it comes with.
> 
> I suspect there is command like:
> 
> stop_showing_me_all_this_uninteresting_stuff = True
> 
> in my future, and dunders is only a small part of that.


The full signature is:

edir([object [, glob=''] [, dunders=True] [, meta=False]])

All four arguments are optional, and dunders and meta are keyword-only. It
is intended to work with Python 2.4 or better. It may not work in Jython on
IronPython, depending on whether or not sys._getframe is supported.

The glob argument is the most interesting, in my opinion. If you give a
non-empty glob, only names matching that glob are returned:

py> dir('', 'is*')
['isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper']


If the glob contains no metacharacters, a plain substring match is done:

py> dir('', 'up')
['isupper', 'upper']


Matches are case-insensitive by default, but can be made case-sensitive by
using a prefix "=". To invert the match (return names which don't match),
use "!" as the prefix. You can use "!=" as a combined prefix.

I haven't yet released this as an independent package as yet, but you can
find it here:

https://code.google.com/p/my-startup-file/

in the "enhanced_dir.py" module.

Consider it beta quality and free for personal use; if anyone wishes a more
formal licence, either wait until I publish it independently, or contact me
off list.




-- 
Steven




More information about the Python-list mailing list