On 1/3/14, 1:59 AM, John Cremona wrote:
there is an easy but dangerous way to do that:matrix(eval("[[1,2],[3,4]]")) --dangerous as the user could enter any string and on running eval it could have nasty side-effects (such as a system call to delete all your files).
It would be safer to either use json.loads (which understands nested lists), or use ast.literal_eval (which is designed to only interpret safe things, like strings, ints, etc.); see http://docs.python.org/2/library/ast.html#ast.literal_eval.
import ast matrix(ast.literal_eval(input_string)) Thanks, Jason -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/groups/opt_out.
