how to use the string '\\.\'
mail at timgolden.me.uk
Mon Apr 9 13:21:52 CEST 2007
> print r'\\.\'
> This line will cause error. I just want to print the
> why the prefix character "r" isn't effective. Thanks!
Because of the way in which Python parses strings,
you can't end a string -- even a raw one -- with
an odd (1, 3, 5 etc) number of backslashes. In
you example, you'd have to do this:
although, depending on what the code was doing,
you might be able to use forward slashes instead;
a surprising number of Microsoft's APIs allow
forward slashes as well as backslashes. Not, however,
anything which is interpreted by the command shell
(which sees a forward slash as a flag indicator) nor
typically anything handled by the Shell subsystem.
More information about the Python-list