Accessing local .py files stored in the workspace

This may be a stupid question (I’m very new), but how does one access local .py files that are stored in the workspace…

I’ve imported a notebook and all my internal references in the format
from folder_in_root_directory.file_name import ClassName
error with “reference not found”

Using the copied path (as well as several variations on this theme)
from '/data/workspace_files/folder_in_root_directory/file_name .py' import ClassName
returns “identifier expected”.

Do I have to use the Library manager and access them through my git repo (I tried briefly and couldn’t figure out how to access files from the repo i’d added either)?

By default /data/workspace_files is not added to sys.path, so Python won’t search for packages there, as a solution you can add it manually:

import sys
sys.path.insert(1, "/data/workspace_files")

You can check that it is correctly added by executing print(sys.path)

Then from folder_in_root_directory.file_name import ClassName should work as expected.

I’ve also created a request to add Workspace Files folder to sys.path automatically when it is attached. Thanks for the question!

1 Like

Update: /data/workspace_files is now included into sys.path for all notebooks.

Thanks again for raising this question!