Making Python code safe for file paths

info-rchitect
Level 6
Making Python code safe for file paths

Hi,

 

When running code that uses the `Pathlib` library in a dataiku jupyter notebook, I am getting errors because it cannot find the files as it can when I run in regular Python.

 

# self.controller.config is a Path instance
self.credentials_file = self.controller.config_dir / 'snowflake_credentials.yaml'

Operating system used: Windows 10

0 Kudos
2 Replies
ZachM
Dataiker

Hi @info-rchitect ,

I've done some experimenting with pathlib on my end, but I haven't experienced any errors.

Could you please provide a complete code example and the error message that you're getting so that I can better help you?

 

Thanks,

Zach

0 Kudos
info-rchitect
Level 6
Author

ZachM,

 

The issue is when trying to debug code in Jupyter notebook vs running in a webapp or a recipe.  I solved the problem by ditching `Pathlib` and just using `os`:

 

os.path.dirname(os.path.realpath(__file__))
0 Kudos