# Converting unicode to 'int'

**URL:** <https://discourse.processing.org/t/converting-unicode-to-int/11047>\
**Category:** Processing.py\
**Created:** [May 9, 2019, 12:43am UTC](https://discourse.processing.org/t/converting-unicode-to-int/11047 "2019-05-09T00:43:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [May 9, 2019, 12:43am UTC](https://discourse.processing.org/t/converting-unicode-to-int/11047/1 "2019-05-09T00:43:54Z")

</div>

Hi,

I’m trying to convert numbers in a column from a CSV file to integers. It seems those numbers are of unicode type. The problem is that I get an error when calling `int()` on that number:

> invalid literal for int() with base 10: ‘ink’

```auto
def setup():
    size(1000, 600, P3D)

    csv = loadTable("citrohanCSV.csv") 
    
    #0 - 1 - 2 - 3 - 4
    #id - x - y - z - links
    
    for ir in xrange(csv.getRowCount()):
        for ic in xrange(csv.getRow(ir).getColumnCount()):
            links = splitTokens(csv.getRow(ir).getString(4)[1:-1], ',')

            print links # returns a number like 127, 3918 or 41
            print type(links) # returns 'unicode'
            print int(links) # returns the error

```

I googled the error but couldn’t find a similar issue.

Questions:

- How can I convert that unicode value to an integer ?
- If that’s not possible what workaround would you suggest ?

([link](https://ufile.io/ozoqt7nq) to the csv file if needed)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [May 9, 2019, 2:03am UTC](https://discourse.processing.org/t/converting-unicode-to-int/11047/2 "2019-05-09T02:03:27Z")

</div>

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

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

But Processing’s **int()** can:  
[Processing.org/reference/intconvert\_.html](http://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-](http://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: 😃

```auto
# 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

```auto
,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]"

```

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [May 9, 2019, 10:16am UTC](https://discourse.processing.org/t/converting-unicode-to-int/11047/3 "2019-05-09T10:16:25Z")

</div>

@GoToLoop Thank you so much for the swift reply and detailed explanations ! It works great now.
