1

So I have a parser set up like such:

parser.add_argument('-f', '--foo', metavar='foo', type=ast.literal_eval, default=[], help="Foo")

And I need to let users enter multiple values if they so desire:

$ python3 foo.py -f [0x01, 0x56, 0xff] -a blah -b blah ...

But whenever I try more than one value in the list I get an EOF error:

...
File "<unknown>", line 1
[0x01,
     ^
SyntaxError: unexpected EOF while parsing

What's the proper way to set up the parser to handle something like this?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
gravytrain
  • 73
  • 5

1 Answers1

3

Just wrap it in "":

python3 foo.py -f "[0x01, 0x56, 0xff]" -a blah -b blah ...

and then just have foo.py (in this case) parse it.

fixatd
  • 1,394
  • 1
  • 11
  • 19