Message176259
| Author |
rurpy2 |
| Recipients |
GraylinKim, bethard, denilsonsa, eric.araujo, rurpy2, zbysz |
| Date |
2012年11月23日.22:26:41 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1353709601.88.0.522815080722.issue12806@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Additional comment loosely related to the ParagraphFormatter offered in previous comment...
[If this is not the right venue -- perhaps a new issue or one of the python mail lists would be better -- please tell me.]
I notice that argparse.ArgumentParser requires a class (as opposed to instance) for the formatter_class parameter. A cursory look at argparse gives me the impression that this is only so that ArgumentParser can instantiate the instance with a 'prog' argument.
If ArgumentParser accepted a HelpFormatter object (rather than a class), then a user could instantiate a custom formatter class with arguments that would customize its behavior. For example, I would be able to write a single ParagraphFormatter class that was instantiated like
formatter = ParagraphFormatter (multiline=False)
or
formatter = ParagraphFormatter (multiline=True)
If one has other requirements, perhaps apply one kind of formatting to description/epilogue text and another to the arguments text, then there is an even greater multiplicity of classes that could be avoided by instantiating a single formatter class with arguments.
So why can't ArgumentParser look at the formatter_class value: if it's a class proceed as now, but if it's an class instance, simply set its ._prog attribute and use it as is:
def _get_formatter(self):
if isinstance (self.formatter_class, <type type>):
return self.formatter_class(prog=self.prog)
else:
self.formatter_class._prog = prog
return self.formatter_class
Of course the "formatter_class" parameter name would then require a little explanation but that's what documentation is for. |
|