# Running python script in robot framework

**URL:** <https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767>\
**Category:** Robot Framework\
**Created:** [2 February 2024 10:58 UTC](https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767 "2024-02-02T10:58:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soma](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Soma](https://forum.robotframework.org/u/Soma)\
**Post date:** [2 February 2024 10:58 UTC](https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767/1 "2024-02-02T10:58:51Z")

</div>

As I’m new to Robot framework. Im trying to run simple robot file

```python
 ***Settings***
Library Process

***Variables***
${PYTHON_SCRIPT} /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/example_script.py

***Test Cases***
Run Python Script
    ${result} = Run Process python ${PYTHON_SCRIPT}
    Should Be Equal As Numbers ${result} 0

```

Python file

```python
# example_script.py

def main():
    print("Hello from example_script.py")

if __name__ == " __main__":
    main()

```

Im not sure of this error .

```python
Example Test                                                                  
==============================================================================
Run Python Script | FAIL |
'<result object with rc 2>' cannot be converted to a floating point number: TypeError: float() argument must be a string or a real number, not 'ExecutionResult'
------------------------------------------------------------------------------
Example Test | FAIL |
1 test, 0 passed, 1 failed

```

Could anyone help on this?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [2 February 2024 12:41 UTC](https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767/2 "2024-02-02T12:41:06Z")

</div>

Hi Soma,

From the [Run Process](https://robotframework.org/robotframework/latest/libraries/Process.html#Run%20Process) Docs:

> Returns a [result object](https://robotframework.org/robotframework/latest/libraries/Process.html#Result%20object) containing information about the execution.

This is not a number but a complete result object, so that would explain your error, perhaps what you wanted is something like:

```python
Should Be Equal As Numbers ${result.rc} 0

```

A little curious why you choose this route when you should be able to use [Evaluate](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Evaluate) something like this:

```python
Evaluate main() modules=${PYTHON_SCRIPT}

```

Remember Robot Framework is written in python, so can easily call any python function internally, no need to go out to a separate python process unless there’s a good reason to do so.

Dave.

---

<div class="post-metadata">

**Author:** ![Soma](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Soma](https://forum.robotframework.org/u/Soma)\
**Post date:** [2 February 2024 13:34 UTC](https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767/3 "2024-02-02T13:34:18Z")

</div>

Thanks Dave.Getting error like this after your inputs,  
Evaluating expression ‘main() modules= /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/example\_script.py’ failed: SyntaxError: invalid syntax (, line 1)

\*\*\* Settings \*\*\*  
Library Process

\*\*\* Variables \*\*\*  
${PYTHON\_SCRIPT} /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/example\_script.py

\*\*\* Test Cases \*\*\*  
Run Python Script  
evaluate main() modules=${PYTHON\_SCRIPT}

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [2 February 2024 13:44 UTC](https://forum.robotframework.org/t/running-python-script-in-robot-framework/6767/4 "2024-02-02T13:44:23Z")

</div>

Hi Soma,

I’ve not used `Evaluate` exactly like that before, so not sure what the exact syntax should be, I’ve only used it with python modules that are in the path.

So normally that would look something like this:

```python
Evaluate main() modules=example_script

```

But that won’t work in your case unless `example_script.py` is in the same folder as your robot file.

Perhaps this will work

```python
Evaluate main() modules=/home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/example_script

```

If not I guess you’ll need to play with it a bit to find the exact syntax to make it work,

Dave.
