On 16/06/2015 00:57, Steven D'Aprano wrote:
I have a function in a module which is intended to be used by importing
that name alone, then used interactively:

     from module import edir
     edir(args)


edir is an enhanced version of dir, and one of the enhancements is that
you can filter out dunder methods. I have reason to believe that people
are split on their opinion on whether dunder methods should be shown by
default or not: some people want to see them, others do not. Since edir
is meant to be used interactively, I want to give people a setting to
control whether they get dunders by default or not.

I have two ideas for this, a module-level global, or a flag set on the
function object itself. Remember that the usual way of using this will be
"from module import edir", there are two obvious ways to set the global:

import module
module.dunders = False

# -or-

edir.__globals__['dunders'] = False


Alternatively, I can use a flag set on the function object itself:

edir.dunders = False


Naturally you can always override the default by explicitly specifying a
keyword argument edir(obj, dunders=flag).

Thoughts and feedback? Please vote: a module global, or a flag on the
object? Please give reasons, and remember that the function is intended
for interactive use.



For interactive use I'd be perfectly happy with just the keyword argument. Why bother toggling something when I can explicitly set it in the call each and every time? If I have to choose it's a flag on the object, just no competition.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to