7

I have a string: '[1, 2, 3]'
I want to convert it to: [1, 2, 3]

I know there was a single bif that I could use, but I couldn't find it or for the life of me recall what it was.

I know someone out there remembers, any help would be greatly appreciated.

Martijn Pieters
  • 889,049
  • 245
  • 3,507
  • 2,997
npengra317
  • 101
  • 2
  • 6

1 Answers1

12

To process a string as if were code:

>>> eval('[1, 2, 3]')
[1, 2, 3]
Tim
  • 38,263
  • 17
  • 115
  • 131
mdurant
  • 21,368
  • 2
  • 33
  • 59