1 | initial version |
You can use the eval
Python function:
sage: s='[(1,2),(2,3)]' ; s
'[(1,2),(2,3)]'
sage: type(s)
<type 'str'>
sage: L = eval(s) ; L
[(1, 2), (2, 3)]
sage: type(L)
<type 'list'>
2 | No.2 Revision |
You can use the eval
Python function:
sage: s='[(1,2),(2,3)]' ; s
'[(1,2),(2,3)]'
sage: type(s)
<type 'str'>
sage: L = eval(s) ; L
[(1, 2), (2, 3)]
sage: type(L)
<type 'list'>
Note however that the string is not preparsed, so you will get Python ints, note Sage integers:
sage: type(L[0][0])
<type 'int'>
To "benefit" from Sage preparsing, you can do:
sage: L = eval(preparse(s)) ; L
[(1, 2), (2, 3)]
sage: type(L[0][0])
<type 'sage.rings.integer.Integer'>