argparse argument post-processing
Mats Wichmann
mats at wichmann.us
Mon Nov 27 15:36:05 EST 2023
On 11/27/23 13:21, Dom Grigonis wrote:
> Thank you, exactly what I was looking for!
>
> One more question following this. Is there a way to have a customisable action? I.e. What if I want to join with space in one case and with coma in another. Is there a way to reuse the same action class?
I've worked more with optparse (the project I work on that uses it has
reasons why it's not feasible to convert to argparse); in optparse you
use a callback function, rather than an action class, and the change to
a callable class is somewhat significant :-; so I'm not really an expert.
The question is how you determine which you want to do - then there's no
problem for the action class's call method to implement it. I presume
you can write an initializer class that takes an extra argument, collect
that and stuff it into an instance variable, then use super to call the
base Action class's initializer with the rest of the args
super().__init__(option_strings=option_strings, *args, **kwargs)
Hopefully someone else has done this kind of thing because now I'm just
guessing!
More information about the Python-list
mailing list