Say the string is like a = "['Hello', 'World']"
. After the conversion, a = ['Hello', 'World']
and the type is a list.
Asked
Active
Viewed 34 times
0

petezurich
- 9,280
- 9
- 43
- 57

KevinTran
- 25
- 9
-
You could use ast.literal_eval – DarkKnight Mar 13 '22 at 07:45
-
`ast.literal_eval()`? – JayPeerachai Mar 13 '22 at 07:45
-
Replace the ' with " and load it as json? – luk2302 Mar 13 '22 at 07:46
1 Answers
-1
It's called expression evaluation. Read about Python's eval() and literal_eval().
Notice that it may be dangerous, so read the docs carefully.

Dennis
- 2,271
- 6
- 26
- 42