# Python 3 Migration: Integer Division

**URL:** <https://discourse.numenta.org/t/python-3-migration-integer-division/3483>\
**Category:** NuPIC\
**Tags:** python\
**Created:** [February 19, 2018, 2:33am UTC](https://discourse.numenta.org/t/python-3-migration-integer-division/3483 "2018-02-19T02:33:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chhenning](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/chhenning/32/3821_2.png) [@chhenning](https://discourse.numenta.org/u/chhenning)\
**Post date:** [February 19, 2018, 2:33am UTC](https://discourse.numenta.org/t/python-3-migration-integer-division/3483/1 "2018-02-19T02:33:22Z")

</div>

One of the hardest parts in the migration process is to find incorrect integer divisions in the python 2.7 nupic code. Python 3 behaves differently as nicely described [here](https://www.codeday.top/2017/08/11/32657.html).

Here are two locations in nupic which I needed to change and let me tell you it takes a long time to find those!

- in [nupic/math/topology.py](https://github.com/numenta/nupic/blob/master/src/nupic/math/topology.py#L50)

```auto
shifted = shifted / dimensions[i] 
to
shifted = shifted // dimensions[i]

```

- in [nupic/encoders/scalar.py](https://github.com/numenta/nupic/blob/master/src/nupic/encoders/scalar.py#L539)

```auto
left = right = start + runLen / 2
to
left = right = start + runLen // 2

```

Anyone has a good idea how to spot those issue? Right now, I need to step through code in two debugger windows side by side and compare data types and values…

---

<div class="post-metadata">

**Author:** ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)\
**Post date:** [February 19, 2018, 4:50pm UTC](https://discourse.numenta.org/t/python-3-migration-integer-division/3483/2 "2018-02-19T16:50:10Z")

</div>

Can you write a regex to find division in the code? Something simple like this can be used as a filter:

```auto
(\s+)?\/(\s+)?

```

![57%20AM](https://canada1.discourse-cdn.com/flex030/uploads/numenta/original/2X/c/c7d24c54c6a443471b8229a9cec4e5181ac52313.png)

---

<div class="post-metadata">

**Author:** ![chhenning](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/chhenning/32/3821_2.png) [@chhenning](https://discourse.numenta.org/u/chhenning)\
**Post date:** [February 21, 2018, 12:31am UTC](https://discourse.numenta.org/t/python-3-migration-integer-division/3483/3 "2018-02-21T00:31:15Z")

</div>

I think we need to find all the divisions where both operands are integers. That’s not something a regex can do. But the article mentions a way to change the division behavior in python 2.7. All a user has to do is to insert this line:

`from __future__ import division`

on top of a module and viola the old python 2.7 code has the same behavior as python 3.

Assuming the current nupic test suit runs through this would be the way to see where it breaks. I haven’t tried it out yet.
