Using argparse
, is there a way to pass an argument that starts with hyphen, like below?
./py_custom_script -d
I'm adding a change to old script that takes an argument, where with and without hyphen the logic is different. Inspired by this post, I thought of only using positional
arg and apply conditional logic internally, but looks like argparse already interprets the one starts with hyphen as an optional
arg.
Note that maintaining backward compatibility is a must for this. Both Py 2.7 and 3.x.