# Revision history [back]

A Sage matrix must have its entries being element of some ring. In other words you can not have a matrix of lists. However it is perfectly fine to have a 2d array (aka a "list of lists").

sage: l = [[1, [2,3]], [2, [5,4]]]
sage: print l
[[1, [2, 3]], [2, [5, 4]]]


To execute some code contained in a string you might use the "eval" or "sage_eval" command

sage: my_string = "[[1, [2,3]], [2, [5,4]]]"
sage: sage_eval(my_string)   # run the Python code from my_string
[[1, [2, 3]], [2, [5, 4]]]


And to read the content of the file these are the standard Python commands open/close

sage: f = open("my_file.data")   # open the file
sage: string = f.read()               # read what is inside (result is a string)
sage: f.close()                          # close the file


A Sage matrix must have its entries being element of some ring. In other words you can not have a matrix of lists. However it is perfectly fine to have a 2d array (aka a "list of lists").

sage: l = [[1, [2,3]], [2, [5,4]]]
sage: print l
[[1, [2, 3]], [2, [5, 4]]]


To execute some code contained in a string you might use the "eval" or "sage_eval" command

sage: my_string = "[[1, [2,3]], [2, [5,4]]]"
sage: sage_eval(my_string)   # run the Python code from my_string
[[1, [2, 3]], [2, [5, 4]]]


And to read the content of the file these are the standard Python commands open/close

sage: f = open("my_file.data")   # open the file
sage: string = f.read()           # read what is inside (result is a string)
sage: f.close()                   # close the file