Cant import random module to Python


#1

I’m trying to import the random module into python and the node throws and exception. Any ideas?

I’ve tried

import random

and

    import sys
    pyt_path = r'C:\Program Files (x86)\\IronPython 2.7\Lib'
    sys.path.append(pyt_path)

to no avail. The IronPython console has no issue with import random and works as expected


Importing python modules into iron python
#2

You would first have to define a path to IronPython’s librar, append it to the system path and then finally import the module.

pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(pyt_path)
import random

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

#Assign your output to the OUT variable.
OUT = random.random()

Works as expected:


Python Nodes Basics
#3

This works for me: (Edit: to late)

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import random
OUT = random.randint(0,9)

#4

Thanks guys. Thought it was going to be something simple I was overlooking!


#5

This works for me too: