There are 2 important points here (from my perspective):
- You do not want to replace all the spaces in the argument input.
- You want to use
argparse
interface.
My best aproax would be to use an argparse.Action
with the function strip
for the string:
import argparse
class StripArgument(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, values.strip())
parser = argparse.ArgumentParser(
prog=f"your program", description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="See '<command> --help' to read about a specific sub-command.")
parser.add_argument(
"-n", "--variable-name", type=str, default='vx', action=StripArgument,
help="Variable name inside something (default: %(default)s)")