-1

I am passing as argument to a python program a list of two strings (in particular to stream geo located tweets from python-twitter). The format is as example: my_python_program.py -l ['-9.215752,36.99','3.73,42.139225'] But when I "argparse" to get that argument I see it is passed as "string" : "['-9.215752,36.99','3.73,42.139225']"

I could recover the original format looking for the "[" "," and "]" character and getting the string between them. But I guess there should be a more "pythonic" way of doing that?

Athena
  • 3,200
  • 3
  • 27
  • 35
mharias
  • 51
  • 1
  • 7

1 Answers1

0

Yes, as comments noted, literal_eval is what you want here.

ast.literal_eval(my_str) will give you a parsed object. Just import ast and literal_eval what comes from argparse.

Athena
  • 3,200
  • 3
  • 27
  • 35