# Setting a .py file variable to a robot framework environment variable for root path

**URL:** <https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209>\
**Category:** Robot Framework\
**Created:** [3 February 2022 16:24 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209 "2022-02-03T16:24:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AAdams001](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aadams001/32/1266_2.png) [@AAdams001](https://forum.robotframework.org/u/AAdams001)\
**Post date:** [3 February 2022 16:24 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209/1 "2022-02-03T16:24:21Z")

</div>

I created a tasks.py file in my project root with the following code to get the root path.

```
import pathlib
import robot.libraries.OperatingSystem

ROOT = pathlib.Path( __file__ ).parent.resolve().as_posix()

```

How do I assign the tasks.py ROOT variable to a robot framework environment variable I can use in a test case to reference a variable file correctly with full path to end up with this:-

Variables ${ROOT}/reference\_libraries/resources/variables/int\_variable.py

instead of:-

Variables C:/Users/AhrenA/Documents/GitHub/yoyo-api-gateway-api-testing/reference\_libraries/resources/variables/int\_variable.py

---

<div class="post-metadata">

**Author:** ![ericbjones](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/ericbjones/32/157_2.png) [@ericbjones](https://forum.robotframework.org/u/ericbjones)\
**Post date:** [3 February 2022 16:29 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209/2 "2022-02-03T16:29:01Z")

</div>

```python
***Settings***
Variables task.py
Variables ${ROOT}/reference_libraries/resources/variables/int_variable.py

```

should work, however, note that this is a builtin variable already

> ${EXECDIR} | An absolute path to the directory where test execution was started from.

[https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#built-in-variables](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#built-in-variables)

So

```python
***Settings***
Variables ${EXECDIR}/reference_libraries/resources/variables/int_variable.py

```

would be better

---

<div class="post-metadata">

**Author:** ![AAdams001](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aadams001/32/1266_2.png) [@AAdams001](https://forum.robotframework.org/u/AAdams001)\
**Post date:** [3 February 2022 17:09 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209/3 "2022-02-03T17:09:43Z")

</div>

That would give me the execution directory and not the project root directory so I get :-

C:\Users\AhrenA\Documents\GitHub\yoyo-api-gateway-api-testing\functional\_tests\partner

when what I want is:-

C:/Users/AhrenA/Documents/GitHub/yoyo-api-gateway-api-testing

which would give me absolute path :-

C:\Users\AhrenA\Documents\GitHub\yoyo-api-gateway-api-testing\reference\_libraries\resources\variables\int\_variable.py

---

<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:** [4 February 2022 01:00 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209/4 "2022-02-04T01:00:04Z")

</div>

Would this work then?

```python
***Settings***
Variables ${EXECDIR}/../../reference_libraries/resources/variables/int_variable.py

```

Seems a lot simpler than including another python library.

---

<div class="post-metadata">

**Author:** ![AAdams001](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aadams001/32/1266_2.png) [@AAdams001](https://forum.robotframework.org/u/AAdams001)\
**Post date:** [4 February 2022 13:10 UTC](https://forum.robotframework.org/t/setting-a-py-file-variable-to-a-robot-framework-environment-variable-for-root-path/3209/5 "2022-02-04T13:10:53Z")

</div>

So changed tact and just made sure to execute all tests from the project root folder, allowing me to use built in ${EXECDIR}
