> -Original Message-
> From:
> [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> rg] On Behalf Of Scott David Daniels
> Sent: 03 October 2006 18:11
> To: python-list@python.org
> Subject: Re: Raw strings and escaping
>
> Matthew Warren wrote:
> >
Matthew Warren wrote:
> Hi,
>
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.
Note something many people don't when looking over the string rules:
astring = r'some things\new things\som
Jon Ribbens <[EMAIL PROTECTED]> wrote:
> Well, hardly *much* harder:
>
> pattern = r"""foo"""
It means you have to always triple quote your raw strings or know in
advance of writing the regular expression which of r'', r"", r'',
r"" is most appropriate. The way it works at the moment
In article <[EMAIL PROTECTED]>, Duncan Booth wrote:
>> I presume there was originally some reason for this bizarre behaviour
>> - it'd be interesting to know what it is/was, if anyone knows?
>>
> See the FAQ for the explanation:
>
> http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-s
Matthew Warren wrote:
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.
raw string literals are parsed in exactly the same way as ordinary string
literals; it's
just the mapping from the stri
Jon Ribbens <[EMAIL PROTECTED]> wrote:
> I presume there was originally some reason for this bizarre behaviour
> - it'd be interesting to know what it is/was, if anyone knows?
>
See the FAQ for the explanation:
http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-bac
In article <[EMAIL PROTECTED]>, Matthew Warren wrote:
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.
String constants in Python are weird - raw strings doubly so.
In a raw string, backslas
"Matthew Warren" <[EMAIL PROTECTED]> wrote:
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.
>
> ..although writing this I think I have solved my own problem. Is \'
> the only thing escaped
Matthew Warren wrote in news:mailman.1152.1159872720.10491.python-
[EMAIL PROTECTED] in comp.lang.python:
> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
It in the docs:
http://docs.python.org/ref/strings.html#l2h-14>
... Specifically, a raw string ca
Alex Martelli wrote:
> John Salerno <[EMAIL PROTECTED]> wrote:
>
>> Alex Martelli wrote:
>>
Now get back to work on your new Nutshell book :-)
>>> Yep, good point!-)
>> Are you working on a new edition? I didn't see any new Python books
>> listed on O'Reilly's site through April, but I'd def
John Salerno <[EMAIL PROTECTED]> wrote:
> Alex Martelli wrote:
>
> >> Now get back to work on your new Nutshell book :-)
> >
> > Yep, good point!-)
>
> Are you working on a new edition? I didn't see any new Python books
> listed on O'Reilly's site through April, but I'd definitely be
> intere
Interesting, so thats where this comes from.
Of course the problem is that I thought that a raw string was a
different animal than a regular string (i.e. truely "raw" where no
characters are special, except of course the closing quote) so parsing
consistency is surprising to an end user (who has a
Alex Martelli wrote:
>> Now get back to work on your new Nutshell book :-)
>
> Yep, good point!-)
Are you working on a new edition? I didn't see any new Python books
listed on O'Reilly's site through April, but I'd definitely be
interested in new versions of the books I plan to get soon (Cookb
[EMAIL PROTECTED] wrote:
> I guess my point is that it is quite surprising that r'\' is not a
> legal way to represent a backslash. I look for consistency in the
> tools that I work with and this except-for-the-last-character exception
> is annoying
you seem to be missing that "exception" you th
Fredrik Lundh wrote:
> "Blackbird" <[EMAIL PROTECTED]> wrote:
>
>> Slightly OT, but here is a crazy little program that shows the power
>> of using raw strings:
>>
>> s=r'print "s=r\'%s\'\n%s"%(s,s)'
>> print "s=r\'%s\'\n%s"%(s,s)
>>
>> When run, this program will print an exact copy of itself.
>
>
"Blackbird" <[EMAIL PROTECTED]> wrote:
> Slightly OT, but here is a crazy little program that shows the power of
> using raw strings:
>
> s=r'print "s=r\'%s\'\n%s"%(s,s)'
> print "s=r\'%s\'\n%s"%(s,s)
>
> When run, this program will print an exact copy of itself.
I'm not sure what the raw strings
Almost off-topic.
Well, okay, completely off-topic.
On Sun, 05 Mar 2006 19:47:07 -0800, plahey wrote:
> I would say that a foolish anything is something to avoid. I don't
> think that anyone would claim that inconsistency is a virtue in a
> computer language (or in anything else for that matter
Slightly OT, but here is a crazy little program that shows the power of
using raw strings:
s=r'print "s=r\'%s\'\n%s"%(s,s)'
print "s=r\'%s\'\n%s"%(s,s)
When run, this program will print an exact copy of itself.
Blackbird
--
http://mail.python.org/mailman/listinfo/python-list
>Alas, somebody will now quote Emerson at you, I fear;-).
Let them come :-)
I almost always see this (mis)quoted as:
"consistency is the hobgoblin of little minds"
which is not really what Emerson said. The full quote is:
"A foolish consistency is the hobgoblin of little minds"
I would say t
[EMAIL PROTECTED] wrote:
> Hi,
>
> thanks for the reply. I was not aware of this in raw strings (and
> frankly, don't like it... but who cares about that :-) )
>
Healthy attitude!
> When I needed embedded quotes in a raw string I went the triple quote
> route:
>
> a = r'''check \' this'''
>
>
<[EMAIL PROTECTED]> wrote:
> thanks for the reply. I can see that there is a choice that needed to
> be made. Before I was aware of the \ issue I just used (yes it has
> come up, but the example is at work) triple quotes to work around the
> embedded quote issue:
>
> x=r'''It's like this "c:\bl
Hi Steven,
thanks for the reply. I was/am aware that raw strings are mainly used
for regular expressions (and franky that was I usually use them for).
I was not aware that they still have "special powers" in raw strings
(thanks for the link!).
This one bit me when I was doing some quick and dirt
Hi Alex,
thanks for the reply. I can see that there is a choice that needed to
be made. Before I was aware of the \ issue I just used (yes it has
come up, but the example is at work) triple quotes to work around the
embedded quote issue:
x=r'''It's like this "c:\blah\" ok?'''
print x
It's like
Hi,
thanks for the reply. I was not aware of this in raw strings (and
frankly, don't like it... but who cares about that :-) )
When I needed embedded quotes in a raw string I went the triple quote
route:
a = r'''check \' this'''
which makes more sense to me.
--
http://mail.python.org/mailman
On Sun, 05 Mar 2006 08:27:31 -0800, plahey wrote:
> Hi Duncan,
>
> thanks for the reply. I figured that this was a technical problem
> associated with the parser.
>
> This one is going on my Python gotchas list. It is really silly from
> an end user perspective to have \ not special in raw str
[EMAIL PROTECTED] wrote:
> Hi Duncan,
>
> thanks for the reply. I figured that this was a technical problem
> associated with the parser.
>
> This one is going on my Python gotchas list. It is really silly from
> an end user perspective to have \ not special in raw strings _except_
> if it is the
<[EMAIL PROTECTED]> wrote:
> Hi Duncan,
>
> thanks for the reply. I figured that this was a technical problem
> associated with the parser.
>
> This one is going on my Python gotchas list. It is really silly from
> an end user perspective to have \ not special in raw strings _except_
> if it i
Hi Duncan,
thanks for the reply. I figured that this was a technical problem
associated with the parser.
This one is going on my Python gotchas list. It is really silly from
an end user perspective to have \ not special in raw strings _except_
if it is the last character.
--
http://mail.pytho
wrote:
> I thought I understood raw strings, then I got bitten by this:
>
> x=r'c:\blah\'
>
> which is illegal! I thought that \ had no special meanning in a raw
> string so why can't it be the last character?
No, the backslash is still special in terms of parsing the string, it
is simply th
29 matches
Mail list logo