Select to view content in your preferred language

list to table

941
2
Jump to solution
05-29-2012 06:00 AM
BartłomiejStaroń
Occasional Contributor
I have list of value:
(a,b,c,d,e,f,aa,bb,cc,dd,ee,ff,aaa,bbb,ccc,ddd,eee,fff...)

and i have table with kolumns:
at,bt,ct,dt,et,ft

I wants  insert to table value in such a scheme:

at,bt,ct,dt,et,ft
_____________
a,b,c,d,e,f
aa,bb,cc,dd,ee,ff
aaa,bbb,ccc,ddd,eee,fff
...

how to do it by insertcursor?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdenil
Frequent Contributor
The first step is looking at your input.

How exactly is your list of values, which you represent as:
(a,b,c,d,e,f,aa,bb,cc,dd,ee,ff,aaa,bbb,ccc,ddd,eee,fff...), actually structured?

Is it really just a long line of values seperated by commas?
If the individual values are strings, are they delimited with quotes, double quotes, or something else that shows them to be strings?
or, are they all numbers?

Idealy , you would like to get your list into an easily-digested form
I would suggest a list of nested lists, with the inner lists as the values for one record.
To wit:
[['a', 'b', 'c', 'd', 'e', 'f'], ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'], ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], ect...]
You could parse a long list with values for 6 items (a-f) like this:
inputList = ['a', 'b', 'c', 'd', 'e', 'f', 'aa', 'bb', 'cc', 'dd',           'ee', 'ff', 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'] count = 1 insideList = [] outList = [] for each in inputList:     insideList.append(each)     count += 1     if count > 6:         outList.append(insideList)         count = 1         insideList = [] print outList


and run your insert cursor like this:
for rowList in outList:     row = inCur.newRow()     row.at = rowList[0]     row.bt = rowList[1]     row.ct = rowList[2]     row.dt = rowList[3]     row.et = rowList[4]     row.ft = rowList[5]     inCur.insertRow(row)


Of course, this suggestion makes alot of assumptions about your input list....

View solution in original post

0 Kudos
2 Replies
markdenil
Frequent Contributor
The first step is looking at your input.

How exactly is your list of values, which you represent as:
(a,b,c,d,e,f,aa,bb,cc,dd,ee,ff,aaa,bbb,ccc,ddd,eee,fff...), actually structured?

Is it really just a long line of values seperated by commas?
If the individual values are strings, are they delimited with quotes, double quotes, or something else that shows them to be strings?
or, are they all numbers?

Idealy , you would like to get your list into an easily-digested form
I would suggest a list of nested lists, with the inner lists as the values for one record.
To wit:
[['a', 'b', 'c', 'd', 'e', 'f'], ['aa', 'bb', 'cc', 'dd', 'ee', 'ff'], ['aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'], ect...]
You could parse a long list with values for 6 items (a-f) like this:
inputList = ['a', 'b', 'c', 'd', 'e', 'f', 'aa', 'bb', 'cc', 'dd',           'ee', 'ff', 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff'] count = 1 insideList = [] outList = [] for each in inputList:     insideList.append(each)     count += 1     if count > 6:         outList.append(insideList)         count = 1         insideList = [] print outList


and run your insert cursor like this:
for rowList in outList:     row = inCur.newRow()     row.at = rowList[0]     row.bt = rowList[1]     row.ct = rowList[2]     row.dt = rowList[3]     row.et = rowList[4]     row.ft = rowList[5]     inCur.insertRow(row)


Of course, this suggestion makes alot of assumptions about your input list....
0 Kudos
BartłomiejStaroń
Occasional Contributor
Thanks, works great.

It is possible to do this by using function "range" in insertCursor

something like: 

for rowList in outList:
    row = inCur.newRow()
    for  row in range(6):
            ......
            inCur.insertRow(row)
   

But I do not know how to correctly write...
0 Kudos