I want to input hex number instead of int number. in type="int" in following,
parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int", default=0, help="index of 11n mcs table. Default: 0.")
How can I do it?
Thanks.
--henry
You can't. You can get a string, and convert that with e.g.
int("FF", 16)
Or you can extend optparse to know a new type, should be possible. That
would have the advantage that the parser already knows about it & can
reject faulty input.
Diez
Workaround for the lazy: '0xff' on the command line instead of 'ff'.
> List,
>
> I want to input hex number instead of int number. in type="int" in
> following,
>
> parser.add_option("-F", "--forcemcs", dest="force_mcs", type="int",
> default=0, help="index of 11n mcs table. Default: 0.")
>
> How can I do it?
Assuming you're talking about "optparse", just prefix the number with "0x"
on the command line:
python myscript.py -F 0xDEAD
If you don't want to have to type the leading "0x", you'll either have to
make yourself a custom type for optparse, or treat it as a string and do
the parsing and error handling afterwards. My recommendation is that you
don't do this: not prefixing your constants if they aren't decimal is an
accident waiting to happen.
--
Rhodri James *-* Wildebeest Herder to the Masses