hex

Discussion in 'Python' started by hong zhang, Nov 19, 2009.

  1. hong zhang

    hong zhang Guest

    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?
    Thanks.

    --henry
    hong zhang, Nov 19, 2009
    #1
    1. Advertising

  2. hong zhang schrieb:
    > 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?


    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
    Diez B. Roggisch, Nov 19, 2009
    #2
    1. Advertising

  3. hong zhang

    Peter Otten Guest

    hong zhang wrote:

    > 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?


    Workaround for the lazy: '0xff' on the command line instead of 'ff'.
    Peter Otten, Nov 19, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    10
    Views:
    6,145
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    450
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    577
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    18,805
  5. tim
    Replies:
    2
    Views:
    1,544
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page