RE: Raw strings and escaping

2006-10-04 Thread Matthew Warren
> -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: > >

Re: Raw strings and escaping

2006-10-03 Thread Scott David Daniels
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

Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
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

Re: Raw strings and escaping

2006-10-03 Thread Jon Ribbens
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

Re: Raw strings and escaping

2006-10-03 Thread Fredrik Lundh
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

Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
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

Re: Raw strings and escaping

2006-10-03 Thread Jon Ribbens
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

Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
"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

Re: Raw strings and escaping

2006-10-03 Thread Rob Williscroft
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

Re: raw strings and \

2006-03-07 Thread John Salerno
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

Re: raw strings and \

2006-03-06 Thread Alex Martelli
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

Re: raw strings and \

2006-03-06 Thread plahey
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

Re: raw strings and \

2006-03-06 Thread John Salerno
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

Re: raw strings and \

2006-03-06 Thread Fredrik Lundh
[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

Re: raw strings and \

2006-03-06 Thread Blackbird
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. > >

Re: raw strings and \

2006-03-06 Thread Fredrik Lundh
"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

Re: raw strings and \

2006-03-06 Thread Steven D'Aprano
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

Re: raw strings and \

2006-03-06 Thread Blackbird
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

Re: raw strings and \

2006-03-05 Thread plahey
>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

Re: raw strings and \

2006-03-05 Thread Steve Holden
[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''' > >

Re: raw strings and \

2006-03-05 Thread Alex Martelli
<[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

Re: raw strings and \

2006-03-05 Thread plahey
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

Re: raw strings and \

2006-03-05 Thread plahey
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

Re: raw strings and \

2006-03-05 Thread plahey
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

Re: raw strings and \

2006-03-05 Thread Steven D'Aprano
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

Re: raw strings and \

2006-03-05 Thread Blackbird
[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

Re: raw strings and \

2006-03-05 Thread Alex Martelli
<[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

Re: raw strings and \

2006-03-05 Thread plahey
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

Re: raw strings and \

2006-03-05 Thread Duncan Booth
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