0

I have a string value that I want to convert to a list. Also once it's converted to a list, I want this kite to act as a variable

control_bag="[["A",("A","B","S","D"),(8,8,kite),(2,2,1)]]"

So, what I am looking as to change the string control_bag to list and kite will be a variable. The result in curve bracket will act as tuple

control_bag = [["A",("A","B","S","D"),(8,8,kite),(2,2,1)]]

I have tried json.loads, but its causing error due to curve brackets

aminrd
  • 2,311
  • 1
  • 12
  • 26
  • Does this answer your question? [How to convert string representation of list to a list?](https://stackoverflow.com/questions/1894269/how-to-convert-string-representation-of-list-to-a-list) – Henry Ecker Apr 03 '21 at 21:19
  • As long as this data is not coming from a potentially malicious source, you can just say `control_bag = eval(control_bag)`. "Curve brackets" are called "parentheses". – Tim Roberts Apr 03 '21 at 21:26
  • 1
    @HenryEcker - `ast.literal_eval` is the way to go for this sort of situation, but the `kite` variable inside the literal makes things tricky. – jakub Apr 03 '21 at 21:28
  • Ah thank you, I missed that. – Henry Ecker Apr 03 '21 at 21:30
  • @TimRoberts eval(control_bag) worked for me like a charm. – Alok Kumar Apr 04 '21 at 11:03

0 Answers0