File call error message (double backslash)

F

Fred

Hi
I am writing on an application, that is supposed to read a file into a
single string:
My program though, when I run it, gives me an error, that the called
file is non existent
'C:\ \Documents and Settings\ \Fred\ \My Documents\ \School\ \Bio'
Is it normal that python adds the space and extra backslash? Because
if I print the path of the called file before the open command, it
normally prints it with only one backslash.
Is there any possiblity of surpressing this?
I am using Python 2.3.5 with Pywin built 163 on Windows.
Thanks for all help
 
M

M.E.Farmer

Hello Fred,
Backslashes are used as an escape and not just in Python ( consider
'\r\n' )
To use a backslash you must escape it with two of them like this: \\
'c:\\windows\\dir'
or you can use a raw string:
r"c:\windows\dir"
or you can use forward slashes. Yes that works ;)
"c:/windows/dir"

Windows uses '\' as a path sep but it also understands '/'.
*nix uses '/' as a path sep.

hth,
M.E.Farmer
 
J

John Machin

Fred said:
Hi
I am writing on an application, that is supposed to read a file into a
single string:
My program though, when I run it, gives me an error, that the called
file is non existent
'C:\ \Documents and Settings\ \Fred\ \My Documents\ \School\ \Bio'
Is it normal that python adds the space and extra backslash? Because
if I print the path of the called file before the open command, it
normally prints it with only one backslash.

The space between the \ \ is NOT normal. Please post the exact (copy
and past!) text of the trace-back and error message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top