Is it possible to use Windows-style command line options with Python?

  argparse, python, windows

Is it possible to make a Python script accept command-line options that are Windows-styled (namely, prefixed with "/" instead of "-"/"–" and using ":" to specify values of options instead of "=")?

So far, I have used argparse and managed to use "/" as a prefix, but I could not make it use ":" as a separator.

parser = argparse.ArgumentParser(prog='PROG', prefix_chars='/')
parser.add_argument('/f')
parser.add_argument('/bar')

#This works with =
print(parser.parse_args('/f X /bar=Y'.split())) #Namespace(bar='Y', f='X')
#Does not work with :
print(parser.parse_args('/f:X /bar:Y'.split())) #blows up

Source: Windows Questions

LEAVE A COMMENT