List to dataset

I have some code which takes a text file and calculates the index weight of each row and counts the number of duplicates. I would like to get the results into a dataset I can bind to a table component, but am not sure how to make the conversion.

[code]path = system.file.openFile(“txt”)

if path != None:
contents = system.file.readFileAsString(path).splitlines()

l=[]

for line in contents:
v0 = (len(line[0:20]) - len(line[0:20].lstrip()))/2
v1 = line[0:30].replace("*","").strip()
v2 = contents.count(line[0:30])
v3 = ‘’

l.extend([v0,v1,v2, v3])

for each in l:
print each[/code]
Output:

[code]0
O “Alternate Hierarchies”
1

1
“WC BOM”
1

2
“A2160”
1

3
“etn110444”
1

4
“03m7185”
2

4
“03m7185”
2

4
“14m7396”
2

4
“14m7396”
2
[/code]

Hi Tim,

Do something like this:

path = system.file.openFile("txt")
   
if path != None:
   contents = system.file.readFileAsString(path).splitlines()

l=[]

for line in contents:
   v0 = (len(line[0:20]) - len(line[0:20].lstrip()))/2
   v1 = line[0:30].replace("*","").strip()
   v2 = contents.count(line[0:30])
   v3 = ''
   l.append([v0,v1,v2,v3])

table = event.source.parent.getComponent("Table")
columns = ["FirstCol","SecondCol","ThirdCol","FourthCol"]
table.data = system.dataset.toDataSet(columns,l)

Best,

1 Like

Thanks Nick