There are many Python modules for parsing and coordinating command-line options (argparse, getopt, blargs, etc.). And Python is blessed with good built-in functions / idioms for handling a variety of function arguments (e.g. default values, * varargs, ** keyword_args). But when I read the code of various projects for top-level functions, I see noticeably less discipline and standardization of function arguments than command-line arguments.
For simple functions, this is not a problem; the built-in argument functions work fine and are more than sufficient. But there are many functionally rich modules, the top-level functions of which provide many different arguments and options (some additional or exclusive), various operating modes, default values, excessive attractions, etc., That is, they have the complexity of the arguments approaching the arguments of the command strings. And they seem to basically process their arguments in special ways.
Given the number of command line processing modules, and how much they have been improved, I would expect at least a few modules to simplify the arguments of complex arguments. But I searched PyPi, stackoverflow and Google without success. So ... are there any functions (not the command line!) Arguments that you would recommend?
--- update with example ---
It is difficult to give a truly simple concrete example, because a precedent does not appear until you deal with a complex module. But here is an attempt to explain the problem in the code: a formatting module with default values that can be overridden when creating a formatting instance or when a function / method is called. If you have only a few options, there are already a lot of help options for handling options, and the option names are repeated ad nauseam.
defaults = { 'indent': 4,
'prefix': None,
'suffix': None,
'name': 'aFormatter',
'reverse': False,
'show_name': False
}
class Formatter(object):
def __init__(self, **kwargs):
self.name = kwargs.get('name', defaults['name'])
self.indent = kwargs.get('indent', defaults['indent'])
self.prefix = kwargs.get('prefix', defaults['prefix'])
self.suffix = kwargs.get('suffix', defaults['suffix'])
self.reverse = kwargs.get('reverse', defaults['reverse'])
self.show_name = kwargs.get('show_name', defaults['show_name'])
def show_lower(self, *args, **kwargs):
indent = kwargs.get('indent', self.indent) or 0
prefix = kwargs.get('prefix', self.prefix)
suffix = kwargs.get('suffix', self.suffix)
reverse = kwargs.get('reverse', self.reverse)
show_name = kwargs.get('show_name', self.show_name)
strings = []
if show_name:
strings.append(self.name + ": ")
if indent:
strings.append(" " * indent)
if prefix:
strings.append(prefix)
for a in args:
strings.append(a.upper() if reverse else a.lower())
if suffix:
strings.append(suffix)
print ''.join(strings)
if __name__ == '__main__':
fmt = Formatter()
fmt.show_lower("THIS IS GOOD")
fmt.show_lower("THIS", "IS", "GOOD")
fmt.show_lower('this IS good', reverse=True)
fmt.show_lower("something!", show_name=True)
upper = Formatter(reverse=True)
upper.show_lower("this is good!")
upper.show_lower("and so is this!", reverse=False)