Ooooh, you’re trying to populate an on-screen table component, not a database table. Ok, that changes things, lets see…
To modify a table component’s data, you must set it to your own DataSet (you don’t get the data and modify it directly) To make a new DataSet, you use fpmi.db.toDataSet(), which takes a list of headers and a list of lists. See the documentation for more details.
You’re on the right track by reading the file in as a string. Try something like this:
[code]path = fpmi.file.openFile(“csv”)
headers = [“Word1”, “Word2”, “Word3”]
data=[]
if path != None:
text = fpmi.file.readFileAsString(path)
line = text.split("\n")
for i in range(len(line)):
#This will get the words as a list of 3 strings
word = line[i].split(",")
# Open up the output console to see the prints
print “%s %s %s” % (word[0], word[1], word[2])
# Add the list as a row of data for our table
data.append(word)
event.source.parent.getComponent(‘StrapTable’).data=fpmi.db.toDataSet(headers,data)
[/code]
I tried this out with the following csv file:
hello,there,moody
1,2,3
and it worked fine. Note that it isn’t very fault tolerant - it needs exactly 3 items in each row, but of course you can make it more fault tolerant if you need to. Also, it will read in everything as a string. If you need some columns an integers, you will need to use python’s int() casting.
Hope this helps,