I have a script.py which is located in a folder called subfolder 1 This folder is located inside the folder named main folder subfolder 2 There is another folder inside the main folder named. I want to open an image in script for subfolder2 and some crop etc. But I do not know how to get the directory right I have tried:
import os rel = " ../subfolder2/1.bmp "impath = os.path.abspath (rel) im = Image.open (attributed) but the error message appears: < Pre> IOError: [Error 2] There is no such file or directory: 'C: \\ user \\ **** \\ desktop \\ mainfolder \\ subfolder2 \\ 1.bmp' Anyway, I'm using Windows Am
mainfolder / subfolder 1 / script.py subfolder 2/1. Bmp P> ... then you can create a path related to script.py . You can now directly with the path relative to the current work You are doing something like this: import os scriptDir = os.path.dirname (__ file__) Accused = os.path.join (scriptDir, '../ subfolder 2/1 bmp') __f Ail __ is an inherent attribute in module, which tells the filesystem path to the module.
Comments
Post a Comment