# Python output diffrence between dynamo and python idle

**URL:** <https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974>\
**Category:** Developers\
**Created:** [January 21, 2019, 2:11pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974 "2019-01-21T14:11:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![2shy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/2shy/32/54014_2.png) [@2shy](https://forum.dynamobim.com/u/2shy)\
**Post date:** [January 21, 2019, 2:11pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/1 "2019-01-21T14:11:01Z")

</div>

Hi all, I stuck on a problem while trying to optimize my dynamo script. This simple method should with every loop add number to random item in a list, but after the process i got sum bigger or smaller than I did loops and adding +1. Here is my code and printscreen. In python idle everything working correct.  
Thank you for help in advance.

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\DLLs')
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
#The inputs to this node will be stored as a list in the IN variables.

looplength = IN[0]
a = IN[1]

import random

def addrandom(n):
	n[random.choice(range(len(n)))] += 1
	

for x in range(IN[0]):
	addrandom(a)
	

OUT = a

```

 ![python%20problem](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/6/e6bd5c8240355439fded4932a2f12f0d089d89b9.jpeg)

EDIT: Python idle was 3.7 Dynamo 2.0 Revit 2019. Looked if random.choice was different in 2.7 but everything seems the same. Looks like a sort of bug for me

.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [January 21, 2019, 11:34pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/2 "2019-01-21T23:34:44Z")

</div>

what version of dynamo is this?  
what version of python are you running in idle?

---

<div class="post-metadata">

**Author:** ![salvatoredragotta](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/salvatoredragotta/32/10078_2.png) [@salvatoredragotta](https://forum.dynamobim.com/u/salvatoredragotta)\
**Post date:** [January 21, 2019, 11:54pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/3 "2019-01-21T23:54:48Z")

</div>

@2shy It’s working for me

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/7/a764620fe0e35af0079ab4bd4bcc8388a14a4ac3.png)

EDIT: Actually it’s not. it gives another sum if disconnect and reconnect the code block with the number 38

---

<div class="post-metadata">

**Author:** ![2shy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/2shy/32/54014_2.png) [@2shy](https://forum.dynamobim.com/u/2shy)\
**Post date:** [January 22, 2019, 8:24am UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/4 "2019-01-22T08:24:29Z")

</div>

Python idle is 3.7 and dynamo is 2.0 Revit 2019, is it any significance?

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [January 22, 2019, 1:43pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/5 "2019-01-22T13:43:20Z")

</div>

ironPython is 2.7 in Dynamo - so maybe 🙂

---

<div class="post-metadata">

**Author:** ![salvatoredragotta](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/salvatoredragotta/32/10078_2.png) [@salvatoredragotta](https://forum.dynamobim.com/u/salvatoredragotta)\
**Post date:** [January 23, 2019, 2:00am UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/6 "2019-01-23T02:00:19Z")

</div>

@2shy I don’t know why but if you change your function as shown below it works.

```
def addrandom(n):
	randomInd = random.choice(range(len(n)))
	n[randomInd] += 1

```

 ![Dynamo%20IronPython](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/9/a9ef9cdead1b0e70a75bedb8c76c6cda66f18f2f.gif)

---

<div class="post-metadata">

**Author:** ![2shy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/2shy/32/54014_2.png) [@2shy](https://forum.dynamobim.com/u/2shy)\
**Post date:** [January 23, 2019, 3:54pm UTC](https://forum.dynamobim.com/t/python-output-diffrence-between-dynamo-and-python-idle/30974/7 "2019-01-23T15:54:55Z")

</div>

Well thats a mystery, big thanks.
