https://prefect.io logo
Title
f

Falk

07/15/2022, 10:04 AM
Hey everyone, I have a bit of an issue with one of my flows. I'm trying to read a yaml file containing configuration like this in my `flow.py`:
with open(f"{os.getcwd()}{file_name}.yaml", "r") as file:
    return yaml.safe_load(file)
Both
flow.py
and
file.yaml
are in the same directory. I also tried setting the path without cwd and like this:
with open(f"{file_name}.yaml", "r") as file:
    return yaml.safe_load(file)
but also no luck. I always get
FileNotFoundError: [Errno 2] No such file or directory: '/file.yaml'
Any ideas what is causing this? Do I have to specify files other than
.py
files for the agent somehow?
d

Dominik Wagner

07/15/2022, 10:23 AM
you might be able to do something like
path = os.path.join(os.path.dirname(os.path.realpath(__file__))),f"{file_name}.yaml")

with open(path, "r") as file:
    return yaml.safe_load(file)
🙌 2
2
f

Falk

07/15/2022, 11:05 AM
That works, thank you @Dominik Wagner 🙏
🎉 2