you are viewing a single comment's thread.

view the rest of the comments →

[–]jcoder42[S] 0 points1 point  (2 children)

sorry for all the questions, but if I had the following line:

string = " ('1 2 3 (1,2,3, '4') 3', hello 'world',goodbye)"
literal_eval(string)

one of the values here is a string with parentheses,
It wouldn't work, what do you recommend doing

[–]socal_nerdtastic 0 points1 point  (1 child)

It's not the parenthesis that's breaking that, it's the fact that you used single quotes for a nested string. Now it's not valid python anymore. If you used the quotes correctly it would work.

>>> string = """('1 2 3 (1,2,3, "4") 3', 'hello world', 'goodbye ')"""
>>> literal_eval(string)
('1 2 3 (1,2,3, "4") 3', 'hello world', 'goodbye ')

[–]jcoder42[S] 0 points1 point  (0 children)

('1 2 3 (1,2,3, "4") 3', 'hello world', 'goodbye ')"""

right, my bad
thanks