Import yaml file in Python

Solved!
Touchpad
Level 1
Import yaml file in Python

Hi Everyone,

I am trying to migrate a model from GitHub repo to Dataiku, where part of the repo contains a Python script calling a yaml file.

I have used the import from GIT feature from the Library Editor. However my python script have no issue calling other .py files. But when trying to call the .yaml file, I get the error message "xxx.yaml not found."

Does anyone know how do I configure this?

0 Kudos
1 Solution
fchataigner2
Dataiker

Python will find .py files using its source paths mechanism, but that'll obviously won't apply when trying to access a file with open() (which is what I'm assuming you're doing with the yaml file). If the yaml file is in the source code along the py files, you could try building its full path from the relative path to the py file where you read it from, since you can have the full path of the python with the __file__ variable.

View solution in original post

0 Kudos
1 Reply
fchataigner2
Dataiker

Python will find .py files using its source paths mechanism, but that'll obviously won't apply when trying to access a file with open() (which is what I'm assuming you're doing with the yaml file). If the yaml file is in the source code along the py files, you could try building its full path from the relative path to the py file where you read it from, since you can have the full path of the python with the __file__ variable.

0 Kudos