I have seen Format ints into string of hex - but I simply cannot figure out how to apply that here:
import argparse
def parse_args(args):
parser = argparse.ArgumentParser(description="Hello hex")
# use lambda to allow for hex parsing https://stackoverflow.com/q/25513043
parser.add_argument('--my_hex', type=lambda x: int(x,0), default=12342, help="set a hex number (default: %(default)s)")
return parser.parse_args(args)
def main(inargs):
args = parse_args(inargs)
If I call this:
$ python3 ../my_hex_script.py --help
usage: my_hex_script.py [-h] [--my_hex MY_HEX]
Hello hex
options:
-h, --help show this help message and exit
--my_hex MY_HEX set a hex number (default: 12342)
... clearly the printout of default value of my_hex
is in decimal.
How do I get it printed in 0x{:04X}
string format?