r prefix bug ... or my lack of understanding?

B

Bill Sneddon

Below is from python 2.3.3 on windows.
I have tryed on Pythonwin and Idle and on
a Solaris unix build 2.2.2.

I know there are work arounds but the behavior
seems a bit strange to me.
Traceback ( File "<interactive input>", line 1
path = r'c:\data\'
^
SyntaxError: EOL while scanning single-quoted string
c:\data\\
 
J

James Henderson

Below is from python 2.3.3 on windows.
I have tryed on Pythonwin and Idle and on
a Solaris unix build 2.2.2.

I know there are work arounds but the behavior
seems a bit strange to me.


Traceback ( File "<interactive input>", line 1
path = r'c:\data\'
^
SyntaxError: EOL while scanning single-quoted string

Your second backslash is escaping the closing quotation mark.
c:\data\\

Try this (with no "r":
c:\data\

James
 
J

James Henderson

Below is from python 2.3.3 on windows.
I have tryed on Pythonwin and Idle and on
a Solaris unix build 2.2.2.

I know there are work arounds but the behavior
seems a bit strange to me.


Traceback ( File "<interactive input>", line 1
path = r'c:\data\'
^
SyntaxError: EOL while scanning single-quoted string


c:\data\\

Fuether to my last post the full details are at:

http://www.python.org/doc/current/ref/strings.html
From which I quote:

r"\" is not a valid string literal (even a raw string cannot end in an odd
number of backslashes). Specifically, a raw string cannot end in a single
backslash (since the backslash would escape the following quote character)

J.
 
S

Skip Montanaro

Bill> Thanks I looked at faqs.org did not see it.

That's because the Python FAQ is not posted to this list/newsgroup. It's
only available on the web. I think faqs.org just culls FAQs from postings.

Skip
 
T

Terry Reedy

Bill Sneddon said:
Below is from python 2.3.3 on windows.
I have tryed on Pythonwin and Idle and on
a Solaris unix build 2.2.2.

I know there are work arounds but the behavior
seems a bit strange to me.

Traceback ( File "<interactive input>", line 1
path = r'c:\data\'
^
SyntaxError: EOL while scanning single-quoted string

c:\data\\

Behaves as per manual.

Note: for almost all usages, even on windows, normal Unix-style forward
slashes works as directory terminators and avoids backslash problems
entirely.

path = 'C:/data/'

Terry J. Reedy
 

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

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,108
Latest member
AlbertEste
Top