I"m getting a list of strings back as an argument from arg_parse, and I would like to convert some of those strings to tuples if it is easily possible.
Here is the list I'm getting from argparse:
['adding_light', '(shift_right_cv,shift_left_cv)']
I wonder how to convert this '(shift_right_cv,shift_left_cv)'
to a tuple.
I don't want to use eval
, as these strings will be inputted by the user (argparse arguments).
Unfortunately, ast.literal.eval() doesn' work -- I get
raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: <_ast.Name object at 0x00000000036A9BA8>
>>>
The suggestions from these threads have been tried out ( not the complicated one):
If there is no easy solution, I may just turn the tuple into a list --so I will get back a nested list from argparse, and see if that is easier to handle. I could also use RE, but I'm concerned about properly covering all cases (user input may possibly break the code).
Thank you.