Re: Raw String Question

2009-03-13 Thread Lie Ryan
MRAB wrote: In Python 3.x a backslash doesn't have a special meaning in a raw string, except that it can prevent a following quote from ending the string, but the backslash is still included. Why? How useful is that? I think it would've been simpler if a backslash had _no_ special effect, not ev

Re: Raw String Question

2009-03-13 Thread MRAB
andrew cooke wrote: MRAB wrote: andrew cooke wrote: MRAB wrote: [...] The other special case is with \u in a Unicode string: >>> ur"\u0041" u'A' this isn't true for 3.0: r"\u0041" '\\u0041' (there's no "u" because it's a string, not a bytes literal) and as far as i can tell, that's cor

Re: Raw String Question

2009-03-13 Thread andrew cooke
MRAB wrote: > andrew cooke wrote: >> MRAB wrote: >> [...] >>> The other special case is with \u in a Unicode string: >>> >>> >>> ur"\u0041" >>> u'A' >> >> this isn't true for 3.0: >> > r"\u0041" >> '\\u0041' >> >> (there's no "u" because it's a string, not a bytes literal) >> >> and as far as

Re: Raw String Question

2009-03-12 Thread MRAB
andrew cooke wrote: MRAB wrote: [...] The other special case is with \u in a Unicode string: >>> ur"\u0041" u'A' this isn't true for 3.0: r"\u0041" '\\u0041' (there's no "u" because it's a string, not a bytes literal) and as far as i can tell, that's correct behaviour according to the d

Re: Raw String Question

2009-03-12 Thread andrew cooke
MRAB wrote: [...] > The other special case is with \u in a Unicode string: > > >>> ur"\u0041" > u'A' this isn't true for 3.0: >>> r"\u0041" '\\u0041' (there's no "u" because it's a string, not a bytes literal) and as far as i can tell, that's correct behaviour according to the docs. andrew -

Re: Raw String Question

2009-03-12 Thread MRAB
Jim Garrison wrote: Tim Chase wrote: >>> r"a\" SyntaxError: EOL while scanning string literal (, line 1) It seems the parser is interpreting the backslash as an escape character in a raw string if the backslash is the last character. Is this expected? Yep...as documented[1], "even a raw s

Re: Raw String Question

2009-03-12 Thread Miles
On Thu, Mar 12, 2009 at 3:28 PM, Jim Garrison wrote: > OK, I'm curious as to the reasoning behind saying that > >   When an 'r' or 'R' prefix is present, a character following a >   backslash is included in the string without change, and all >   backslashes are left in the string. > > which sounds

Re: Raw String Question

2009-03-12 Thread Albert Hopkins
> > Yep...as documented[1], "even a raw string cannot end in an odd number > > of backslashes". > > So how do you explain this? > > >>> r'a\'b' > "a\\'b" That doesn't "end in an odd number of backslashes." Python is __repr__esenting a raw string as a "regular" string. Literally they

Re: Raw String Question

2009-03-12 Thread Jim Garrison
Tim Chase wrote: >>> r"a\" SyntaxError: EOL while scanning string literal (, line 1) It seems the parser is interpreting the backslash as an escape character in a raw string if the backslash is the last character. Is this expected? Yep...as documented[1], "even a raw string cannot end in a

Re: Raw String Question

2009-03-12 Thread Duncan Booth
Jim Garrison wrote: > OK, I'm curious as to the reasoning behind saying that > > When an 'r' or 'R' prefix is present, a character following a > backslash is included in the string without change, and all > backslashes are left in the string. > > which sounds reasonable, but then sa

Re: Raw String Question

2009-03-12 Thread Nick Craig-Wood
Jim Garrison wrote: > >>> r"a\b" >'a\\b' > >>> r"a\" >SyntaxError: EOL while scanning string literal (, line 1) > >>> r"a\ " >'a\\ ' > >>> r"a\"" >'a\\"' > > It seems the parser is interpreting the backslash as an escape > character in a raw string if the backslash is th

Re: Raw String Question

2009-03-12 Thread Jim Garrison
Tim Chase wrote: >>> r"a\" SyntaxError: EOL while scanning string literal (, line 1) It seems the parser is interpreting the backslash as an escape character in a raw string if the backslash is the last character. Is this expected? Yep...as documented[1], "even a raw string cannot end in a

Re: Raw String Question

2009-03-12 Thread Tim Chase
>>> r"a\" SyntaxError: EOL while scanning string literal (, line 1) It seems the parser is interpreting the backslash as an escape character in a raw string if the backslash is the last character. Is this expected? Yep...as documented[1], "even a raw string cannot end in an odd number of b

Raw String Question

2009-03-12 Thread Jim Garrison
I'm an experienced Perl developer learning Python, but I seem to be missing something about raw strings. Here's a transcript of a Python shell session: Python 3.0 (r30:67507, Dec 3 2008, 20:14:27) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more infor