How can I open files in directories below the working directory in Jupyter with Python on Linux?

2412 views python
3

I am an intermediate Python and Jupyter developer, but I am having an issue with what should seem a simple problem.

Problem

When I open a notebook and call the rsf package command to input a file, I can read some rsf files in a given directory but not other rsf files in the same directory. All files are not empty.

with rsf.input(fname) as sf:

The error is: FileNotFoundError returned by the following line:

with(open(filename, 'r') as fh:

The only reason I suspect it can read some files and not others is that the readable ones were created first and possibly remain in a path in memory whereas new files are not on that path.

Attempted Solutions

1) I have used sys.path.append('/ <path from Jupyter working directory to file directory> /), but still only some rsf files, not all rsf files, can be read.

2) I have deleted the above sys.path.append(...) command and called sys.path.pop() to remove the file directory, and still the rsf package can read the files created earlier and not the new rsf files.

3) I printed the sys.path to confirm and see that only python36 related directories are on the path, no custom directories I have added. I checked this after step 2. The earlier rsf files can be read even though their directory is not on the sys.path.

Is there another working directory path that I need to load and possibly I have an old copy of a working directory list of files in memory?

answered question
GiovaniSalazar

Can you add your code..?

Add a Comment

1 Answer

4
jnnnnn 0 Comments

Try using os.listdir to see what files are visible to Python.

posted this

Please login first before posting an answer.