# Range function in python script

**URL:** <https://forum.dynamobim.com/t/range-function-in-python-script/81588>\
**Category:** Revit\
**Tags:** python, dynamo\
**Created:** [September 29, 2022, 3:13am UTC](https://forum.dynamobim.com/t/range-function-in-python-script/81588 "2022-09-29T03:13:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![AM3D.BIM.STUDIO](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/am3d.bim.studio/32/127441_2.png) [@AM3D.BIM.STUDIO](https://forum.dynamobim.com/u/AM3D.BIM.STUDIO)\
**Post date:** [September 29, 2022, 3:13am UTC](https://forum.dynamobim.com/t/range-function-in-python-script/81588/1 "2022-09-29T03:13:08Z")

</div>

Hello.  
I am trying to learn PythonScript within dynamo and ran into a problem.  
It happens that I want to create a range with data as it was done in a CODEBLOCK but it happens that it gives an error and it only admits integers on the other hand I cannot place quantity limits with the “#” either and it becomes a problem I thought it would be as simple as in the CODEBLOCK.  
My request is how could I create a FUNCTION in PYTHONSCRIPT that allows me to enter integer and decimal values as well as allow me to enter quantity limits… in a nutshell, how could I replicate the function that the codeblock has in terms of ranges…?? ?  
I leave some reference images there… I haven’t started anything CODE because I don’t understand how I should start… thank you very much for your help.

 ![01_CREANDO DEFINICIONES DE RANGOS_2022-09-28_09-59-37](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/9/e9b25d13523f0e365d496444f6f8facf9e545ea6.png)  
 ![04_RANGOS EN PYTHON SCRIPT](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/b/0be09316a14317560eaeef9e292a3975c8afec94.jpeg)

---

<div class="post-metadata">

**Author:** ![leonard.moelders](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/leonard.moelders/32/108216_2.png) [@leonard.moelders](https://forum.dynamobim.com/u/leonard.moelders)\
**Post date:** [September 29, 2022, 6:37am UTC](https://forum.dynamobim.com/t/range-function-in-python-script/81588/2 "2022-09-29T06:37:34Z")

</div>

```auto
import clr
import sys
sys.path.append('C:\Program Files (x86)\IronPython 2.7\Lib')

start = IN[0]
stop = IN[1]
step = IN[2]

OUT = range(start, stop, step)

```

You need to click on “+” in the python node to create 3 inputs and connect your values (start, stop, step) accordingly.

A good start with python in dynamo is this:

> **[Take Dynamo Further 🚀](https://dynamopythonprimer.gitbook.io/dynamo-python-primer/)**
>
> Using Python will take your Dynamo definitions to the next level

> **[Untangling Python: A Crash Course on Dynamo‘s Python Node](https://www.autodesk.com/autodesk-university/class/Untangling-Python-Crash-Course-Dynamos-Python-Node-2017#video)**
>
> This class will walk through the basic concepts involved in usingPython within the Dynamo Environment.We will cover some basic Python concepts that are needed to write a few code samples,as well as explain in detail all the boiler plate and import...

---

<div class="post-metadata">

**Author:** ![AM3D.BIM.STUDIO](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/am3d.bim.studio/32/127441_2.png) [@AM3D.BIM.STUDIO](https://forum.dynamobim.com/u/AM3D.BIM.STUDIO)\
**Post date:** [September 29, 2022, 4:53pm UTC](https://forum.dynamobim.com/t/range-function-in-python-script/81588/3 "2022-09-29T16:53:16Z")

</div>

Good morning, thanks for commenting… I’ve tried what you suggested but it doesn’t work… the range method keeps asking only for integers… how to enter decimal numbers…??? ?

 ![05_RANGOS EN PYTHON SCRIPT](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/5/759931db939ece951ab1b4554f082ae4f85d1e29.jpeg)

---

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [September 29, 2022, 7:20pm UTC](https://forum.dynamobim.com/t/range-function-in-python-script/81588/4 "2022-09-29T19:20:23Z")

</div>

Hello,  
you can build custom generators (works on both engine)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/4/e4352a9dabdab1bba5cc481437220e283620fc46.png)

drange

```auto
import sys
import clr

def drange(start, end, step):
	i = start
	while round(i, 10) < end:
		yield i
		i += step
		
OUT = list(drange(IN[0], IN[1], IN[2]))

```

linspace

```auto
import sys
import clr

def linspace(start, end, num):
	step = (end - start) * 1.0 / num 
	i = start
	while round(i, 10) < end:
		yield i
		i += step
		
OUT = list(linspace(IN[0], IN[1], IN[2]))

```

or you can use numpy with CPython3
