A go to method for reading things into a list is the readlines() method for files.
However, your data is a bit tricky since you have quotation marks. Note, these are not the usual quotation marks around a string declaration, but actual text.
We iterate through the values and remove them, then convert the remaining string to integer. We then append each row to a matrix:
with open('data.txt', 'r') as f:
data = f.readlines() # read raw lines into an array
cleaned_matrix = []
for raw_line in data:
split_line = raw_line.strip().split(",") # ["1", "0" ... ]
nums_ls = [int(x.replace('"', '')) for x in split_line] # get rid of the quotation marks and convert to int
cleaned_matrix.append(nums_ls)
print cleaned_matrix
output:
[[0, 0, 0, 0, 1, 0],
[0, 0, 0, 2, 1, 0]]
csvlibrary to read the file and cast each value tointwhile you're reading the rows. You could possibly just split each row on commas and cast to int, but if it's a CSV, you might as well use the built-in library.