Pathname problem
Tim Peters
tim.one at comcast.net
Tue Apr 8 15:48:19 EDT 2003
[bourassa]
> Hi there. I am just trying to load files using PIL. I get the following:
>
> im=Image.open("C:\MATLAB6p1\toolbox\pout.tif")
> Traceback (most recent call last):
> File "<pyshell#13>", line 1, in ?
> im=Image.open("C:\MATLAB6p1\toolbox\pout.tif")
> File "C:\Python22\Lib\site-packages\PIL\Image.py", line 1479, in open
> fp = __builtin__.open(fp, "rb")
> IOError: [Errno 2] No such file or directory:
> 'C:\\MATLAB6p1\toolbox\\pout.tif'
>
> I have stepped through and if the file in C:\ or C:\MATLAB6p1 it loads
> with no problem. The minute I try to get it out of "toolbox" (which
> exists) I get the above error. I'm using PIL-1.1.4a3.win32 on a Win2K
> PIV. TIA.
"\t" is a tab character, not a backslash followed by the letter t. Easiest
is to use forward slashes:
im = Image.open("C:/MATLAB6p1/toolbox/pout.tif")
You could instead use a raw string:
im = Image.open(r"C:\MATLAB6p1\toolbox\pout.tif")
or double your backslashes:
im = Image.open("C:\\MATLAB6p1\\toolbox\\pout.tif")
or paste path components together via os.path.join() for a wholly portable
approach.
More information about the Python-list
mailing list