Issue
I am attempting to run a function on a directory of images in my OneDrive folder. When I use the shell command in the jupyter notebook:
!ls ../OneDrive\ -\ University/centralschool
I get a list of all my .tif images. However, when I attempt to call the directory through my python function:
for f in sorted(listdir('../OneDrive\ -\ University/centralschool')):
print(f)
I get the classic error:
FileNotFoundError: [Errno 2] No such file or directory: '../OneDrive\\ -\\ University/centralschool'
I've never called folders from my OneDrive folder before, is this not possible since it is cloud-based? Also the way that you call a folder that has spaces in it tripped me up but once I got it to work in the shell command I thought it would transfer into my python function but that wasn't the case.
Lastly, the script I am working in is set up as follows
Desktop
Documents
OneDrive
Image_Work
|
|__script.ipynb
|__otherscripty.ipynb
With the script I'm using defined as "script", thus i've tried starting my directory call with ./
and ../
. I am using jupyter notebook through Anaconda.
Solution
Because you have the file name inside a string in python, you don't need to worry about escaping the spaces. (You also wouldn't need to do so on the command line if you put the file name into quotes.) The issue has nothing to do with OneDrive.
This should work:
for f in sorted(listdir('../OneDrive - University/centralschool')):
print(f)
Answered By - baileythegreen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.