I've got a .csv file and I need to get some information from it. If I open the file, I can see two lines in it, that says "data" and "notes", and I need to get the information that these two variables have.
When I open the .csv file, it shows these lines:
data =
[0,1,2,3,4,5,3,2,3,4,5,]
notes = [{"text": "Hello", "position":(2,3)}, {"text": "Bye", "position":(4,5)}]
To open the file I use:
import csv
class A()
def __init__(self):
#Some stuff in here
def get_data(self):
file = open(self.file_name, "r")
data = csv.reader(file, delimiter = "\t)
rows = [row for row in data]
Now, to read the information in data, I just write:
for line in row[1][0]:
try:
value_list = int(line)
print value_list
except ValueError:
pass
And, with this I can create another list with these values and print it. Now, I need to read the data from "notes", as you can see, it is a list with dictionaries as elements. What I need to do, is to read the "position" element inside each dictionary and print it.
This is the code that I have:
for notes in row[3][0]:
if notes["position"]:
print notes["position"]
But this, gives me this error:
TypeError: string indices must be integers, not str
How can I access these elements of each dictionary and then print it? Hope you can help me.
This is the .csv file from where I am trying to get the information.

.csvfile.