[Tutor] ok

Emil Styrke emil@lysator.liu.se
04 Sep 2002 18:33:59 +0200


"Morne" <fromclay@maxitec.co.za> writes:

> ok my log file is saved in C:\my documents\ppp.log

...

> def main():
>     f=open("C:\my documents\ppp.log","r")
                ^            ^

Here is the error.  Backslashes act as special "escape" characters
inside python strings.  There are several escape sequences you can put
in your strings to produce characters that are hard or impossible to
write explicitly.  For example, "\n" inserts a newline into your
string, and "\t" inserts a tab character.  You have two options here:

1. Double all the backslashes ("C:\\my documents\\ppp.log"). "\\" is
   the escape sequence to insert a backslash into the string.

2. Put an "r" before the string, like this:

>>> r"C:\my documents\ppp.log"

   This will make python interpret the string as a "raw" string, thus
   ignoring any escape sequences.

HTH
        /Emil