Converting unicode to 'int'

PApplet::splitTokens() returns a String[] array:
Processing.org/reference/splitTokens_.html

However, I don’t think Python’s native int() can convert whole arrays:
Py.Processing.org/reference/intconvert.html

But Processing’s int() can:
Processing.org/reference/intconvert_.html

However, that’s not its actual internal function’s name. It is parseInt() instead:
Processing.GitHub.io/processing-javadocs/core/processing/core/PApplet.html#parseInt-java.lang.String:A-

And as expected, PApplet::parseInt() isn’t available globally.
We need to use the this variable in order to access it: this.parseInt()

Anyways, that’s what I’ve come up with: :smiley:

# https://Discourse.Processing.org/t/converting-unicode-to-int/11047/2
# GoToLoop (v1.1.1) (2019/May/08)

FILENAME = 'citrohancsv.csv'
DELIMS = '[, ]'
ID, LINKS = 0, 4

parseInt = this.parseInt

csv = loadTable(FILENAME, 'header')

for tr in csv.rows():
    links = parseInt(splitTokens(tr.getString(LINKS), DELIMS))
    print tr.getInt(ID), links

print csv.columnTitles # ,x,y,z,links

exit()

citrohancsv.csv

,x,y,z,links
0,0.0,-25.0,111.0,"[1, 4, 5, 10, 273, 305]"
1,0.0,-25.0,143.0,"[0, 4, 11, 273, 274]"
2,0.0,-2.0,111.0,"[3, 6, 12, 13, 285, 286]"
3,0.0,-2.0,143.0,"[2, 7, 12, 286, 294]"
4,0.0,-27.0,145.0,"[0, 1, 5, 7, 8, 11, 12, 287, 288]"
5,0.0,-27.0,102.0,"[0, 4, 6, 8, 9, 10, 13, 287, 288, 304, 334]"
6,0.0,-12.0,111.0,"[2, 5, 7, 10, 11, 13, 285, 293]"
7,0.0,-12.0,143.0,"[3, 4, 6, 11, 12, 293, 294]"
8,0.0,-47.0,145.0,"[4, 5, 9, 287, 303]"
9,0.0,-47.0,102.0,"[5, 8, 303, 304]"
3 Likes