Re: python3 raw strings and \u escapes

2012-06-15 Thread Jason Friedman
>> This is a related question. >> >> I perform an octal dump on a file: >> $ od -cx file >> 000   h   e   l   l   o       w   o   r   l   d  \n >>            6568    6c6c    206f    6f77    6c72    0a64 >> >> I want to output the names of those characters: >> $ python3 >> Python 3.2.3 (default,

Re: python3 raw strings and \u escapes

2012-06-15 Thread MRAB
On 16/06/2012 00:42, Jason Friedman wrote: This is a related question. I perform an octal dump on a file: $ od -cx file 000 h e l l o w o r l d \n 65686c6c206f6f776c720a64 I want to output the names of those characters: $ python3 Pyth

Re: python3 raw strings and \u escapes

2012-06-15 Thread Jason Friedman
This is a related question. I perform an octal dump on a file: $ od -cx file 000 h e l l o w o r l d \n 65686c6c206f6f776c720a64 I want to output the names of those characters: $ python3 Python 3.2.3 (default, May 19 2012, 17:01:30) [GCC

Re: python3 raw strings and \u escapes

2012-05-31 Thread ru...@yahoo.com
On 05/31/2012 03:10 PM, Chris Angelico wrote: > On Fri, Jun 1, 2012 at 6:28 AM, ru...@yahoo.com wrote: >> ... a lexer module that is structured as many >> dozens of little functions, each with a docstring that is >> a regex string. > > This may be a good opportunity to take a step back and ask you

Re: python3 raw strings and \u escapes

2012-05-31 Thread Chris Angelico
On Fri, Jun 1, 2012 at 6:28 AM, ru...@yahoo.com wrote: > ... a lexer module that is structured as many > dozens of little functions, each with a docstring that is > a regex string. This may be a good opportunity to take a step back and ask yourself: Why so many functions, each with a regular expr

Re: python3 raw strings and \u escapes

2012-05-31 Thread ru...@yahoo.com
On 05/30/2012 09:07 AM, ru...@yahoo.com wrote: > On 05/30/2012 05:54 AM, Thomas Rachel wrote: >> Am 30.05.2012 08:52 schrieb ru...@yahoo.com: >> >>> This breaks a lot of my code because in python 2 >>>re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] >>> but in python 3 (the result of

Re: python3 raw strings and \u escapes

2012-05-30 Thread jmfauth
On 30 mai, 08:52, "ru...@yahoo.com" wrote: > In python2, "\u" escapes are processed in raw unicode > strings.  That is, ur'\u3000' is a string of length 1 > consisting of the IDEOGRAPHIC SPACE unicode character. > > In python3, "\u" escapes are not processed in raw strings. > r'\u3000' is a string

Re: python3 raw strings and \u escapes

2012-05-30 Thread jmfauth
On 30 mai, 13:54, Thomas Rachel wrote: > Am 30.05.2012 08:52 schrieb ru...@yahoo.com: > > > > > This breaks a lot of my code because in python 2 > >        re.split (ur'[\u3000]', u'A\u3000A') ==>  [u'A', u'A'] > > but in python 3 (the result of running 2to3), > >        re.split (r'[\u3000]', 'A\

Re: python3 raw strings and \u escapes

2012-05-30 Thread ru...@yahoo.com
On 05/30/2012 10:46 AM, Terry Reedy wrote: > On 5/30/2012 2:52 AM, ru...@yahoo.com wrote: >> In python2, "\u" escapes are processed in raw unicode >> strings. That is, ur'\u3000' is a string of length 1 >> consisting of the IDEOGRAPHIC SPACE unicode character. > > That surprised me until I rechec

Re: python3 raw strings and \u escapes

2012-05-30 Thread Serhiy Storchaka
On 30.05.12 14:54, Thomas Rachel wrote: There is a 3rd one: use r'[ ' + '\u3000' + ']'. Not very nice to read, but should do the trick... Or r'[ %s]' % ('\u3000',). -- http://mail.python.org/mailman/listinfo/python-list

Re: python3 raw strings and \u escapes

2012-05-30 Thread Terry Reedy
On 5/30/2012 2:52 AM, ru...@yahoo.com wrote: In python2, "\u" escapes are processed in raw unicode strings. That is, ur'\u3000' is a string of length 1 consisting of the IDEOGRAPHIC SPACE unicode character. That surprised me until I rechecked the fine manual and found: "When an 'r' or 'R' pre

Re: python3 raw strings and \u escapes

2012-05-30 Thread ru...@yahoo.com
On 05/30/2012 05:54 AM, Thomas Rachel wrote: > Am 30.05.2012 08:52 schrieb ru...@yahoo.com: > >> This breaks a lot of my code because in python 2 >>re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] >> but in python 3 (the result of running 2to3), >>re.split (r'[\u3000]', 'A\u30

Re: python3 raw strings and \u escapes

2012-05-30 Thread Arnaud Delobelle
On 30 May 2012 12:54, Thomas Rachel wrote: > There is a 3rd one: use   r'[ ' + '\u3000' + ']'. Not very nice to read, but > should do the trick... You could even take advantage of string literal concatenation:) r'[' '\u3000' r']' -- Arnaud -- http://mail.python.org/mailman/listinfo/python

Re: python3 raw strings and \u escapes

2012-05-30 Thread Devin Jeanpierre
On Wed, May 30, 2012 at 2:52 AM, ru...@yahoo.com wrote: > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) > > And is there no choice for me but to choose between the two > poo

Re: python3 raw strings and \u escapes

2012-05-30 Thread Thomas Rachel
Am 30.05.2012 08:52 schrieb ru...@yahoo.com: This breaks a lot of my code because in python 2 re.split (ur'[\u3000]', u'A\u3000A') ==> [u'A', u'A'] but in python 3 (the result of running 2to3), re.split (r'[\u3000]', 'A\u3000A' ) ==> ['A\u3000A'] I can remove the "r" prefix from

Re: python3 raw strings and \u escapes

2012-05-30 Thread Andrew Berg
On 5/30/2012 1:52 AM, ru...@yahoo.com wrote: > Was there a reason for dropping the lexical processing of > \u escapes in strings in python3 (other than to add another > annoyance in a long list of python3 annoyances?) To me, this would be a Python 2 annoyance since I would expect r'\u3000' to be li

python3 raw strings and \u escapes

2012-05-30 Thread ru...@yahoo.com
In python2, "\u" escapes are processed in raw unicode strings. That is, ur'\u3000' is a string of length 1 consisting of the IDEOGRAPHIC SPACE unicode character. In python3, "\u" escapes are not processed in raw strings. r'\u3000' is a string of length 6 consisting of a backslash, 'u', '3' and th

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

Raw strings and escaping

2006-10-03 Thread Matthew Warren
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. ..although writing this I think I have solved my own problem. Is \' the only thing escaped in a raw string so you can place ' in a raw string? Alt

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:

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

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

raw strings and \

2006-03-05 Thread plahey
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? making me do: x=r'c:\blah' '\\' is just silly... -- http://mail.python.org/mailman/listinfo/python-l