Image.open( "C:\test.jpg") is this wrong ?

Matt McCredie mccredie at gmail.com
Mon Aug 27 12:28:49 EDT 2007


> Image.open("C:\test.jpg")  # this is what I have right now. And it can't
> find the file or directory. The file is there (it is everywhere on my
> computer now!!!)
>
> I found some code where they apply the file path to a variable in single
> quotes. Is that how it is done. Also I thought single quotes were for
> characters not strings.

In python there is no difference between single and double quotes. You
are close, but the "C:\test.jpg", sees the "\t" as the escape sequence
for `tab'. You can generally use three things:

"C:\\test.jpg" where "\\" is the escape sequence for a single backslash `\'

You can use a raw string: r"C:\test.jpg" which disables escaping.

You can use forward slashes "C:/test.jpg", which might look funny but does work.

Read more here:
http://docs.python.org/tut/node5.html#SECTION005120000000000000000

Matt



More information about the Python-list mailing list