String comparison

Matt Gerrans matt_gerrans at hp.com
Thu Aug 22 21:27:53 CEST 2002


> There was some whitespace junk in the file.  The following works fine.
> ...
> f = open("D:\PythonServerMonitor\KWE1144589.dat","r")

As Terry Reedy mentioned, you have unescaped backslashes in your filename,
but in this case, you are getting lucky, because neither '\P' nor '\K' are
escape seqences.   However, if any part of your path or file name started
with a character that is ('b', 'n', 't' and so on), you'd get an exception
every time.

To be safe, you should always use a raw string for the file name like so:
   f = open( r"D:\PythonServerMonitor\KWE1144589.dat", "r" )

or escape the backslashes like so:
   f = open( "D:\\PythonServerMonitor\\KWE1144589.dat", "r" )






More information about the Python-list mailing list