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
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
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
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
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
-
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
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
> > 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
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
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
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
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
>>> 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
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
14 matches
Mail list logo