Re: Raw string statement (proposal)

2018-05-27 Thread Dan Stromberg
On Thu, May 24, 2018 at 9:34 PM, Mikhail V wrote: > Hi. > I've put some thoughts together, and > need some feedback on this proposal. > Main question is: Is it convincing? > Is there any flaw? > My own opinion - there IS something to chase. > Still the justification for such syntax is hard. > Th

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:21 PM, Chris Angelico wrote: > > I'm done. Argue with brick walls for the rest of eternity if you like. I see you like me, but I can reciprocate your feelings. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/

Re: Raw string statement (proposal)

2018-05-26 Thread Chris Angelico
On Sun, May 27, 2018 at 5:13 AM, Mikhail V wrote: > On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano >> temp = >>| Mikhail's syntax for {65290} is {65290} >> Can you see the problem yet? How does your collapse function f() >> distinguish between the escape code {65290} and the literal string

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano wrote: > On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote: > >>> Here is a string assigned to name `s` using Python's current syntax: >>> >>> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere" >>> >>> How do you represent that assignment using your

Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote: >> Here is a string assigned to name `s` using Python's current syntax: >> >> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere" >> >> How do you represent that assignment using your syntax? > > Hope its not mandatory to decipher your random exam

Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:55 AM, Steven D'Aprano wrote: > On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote: > >> On Fri, May 25, 2018 at 1:15 PM, bartc wrote: > [...] >>> One problem here is how to deal with embedded non-printable characters: >>> CR, LF and TAB might become part of the normal

Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote: > On Fri, May 25, 2018 at 1:15 PM, bartc wrote: [...] >> One problem here is how to deal with embedded non-printable characters: >> CR, LF and TAB might become part of the normal source text, but how >> about anything else? Or would you only al

Re: Raw string statement (proposal)

2018-05-25 Thread Mikhail V
On Fri, May 25, 2018 at 1:15 PM, bartc wrote: > On 25/05/2018 05:34, Mikhail V wrote: > > I had one big problem with your proposal, which is that I couldn't make head > or tail of your syntax. Such a thing should be immediately obvious. > > (In your first two examples, what IS the exact string th

Re: Raw string statement (proposal)

2018-05-25 Thread bartc
On 25/05/2018 05:34, Mikhail V wrote: Proposal --- Current proposal suggests adding syntax for the "raw text" statement. This should enable the possibility to define text pieces in source code without the need for interpreted characters. Thereby it should solve the mentioned issues. Add

Re: Raw string substitution problem

2010-01-01 Thread Aahz
In article <7p2juvfu8...@mid.individual.net>, Gregory Ewing wrote: >MRAB wrote: >> >> In simple cases you might be replacing with the same string every time, >> but other cases you might want the replacement to contain substrings >> captured by the regex. > >But you can give it a function that ha

Re: Raw string substitution problem

2009-12-19 Thread Rhodri James
On Fri, 18 Dec 2009 17:58:08 -, Alan G Isaac wrote: On 12/17/2009 7:59 PM, Rhodri James wrote: "re.compile('a\\nc')" passes a sequence of four characters to re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own interpretation: 'a' passes through as is, '\' flags an escape w

Re: Raw string substitution problem

2009-12-18 Thread Steven D'Aprano
On Sat, 19 Dec 2009 02:24:00 +, MRAB wrote: > Gregory Ewing wrote: >> MRAB wrote: >> >>> In simple cases you might be replacing with the same string every >>> time, but other cases you might want the replacement to contain >>> substrings captured by the regex. >> >> But you can give it a fun

Re: Raw string substitution problem

2009-12-18 Thread MRAB
Gregory Ewing wrote: MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. But you can give it a function that has access to the match object and can produce whatever repl

Re: Raw string substitution problem

2009-12-18 Thread Gregory Ewing
MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. But you can give it a function that has access to the match object and can produce whatever replacement string it want

Re: Raw string substitution problem

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:59 AM, Alan G Isaac wrote: On 12/18/2009 12:17 PM, MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. Of course that "conversion" is needed in the repla

Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac
On 12/18/2009 12:17 PM, MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. Of course that "conversion" is needed in the replacement. But e.g. Vim substitutions handle th

Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac
On 12/17/2009 7:59 PM, Rhodri James wrote: "re.compile('a\\nc')" passes a sequence of four characters to re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own interpretation: 'a' passes through as is, '\' flags an escape which combined with 'n' produces the newline character (0x0a),

Re: Raw string substitution problem

2009-12-18 Thread MRAB
Gregory Ewing wrote: MRAB wrote: Regular expressions and replacement strings have their own escaping mechanism, which also uses backslashes. This seems like a misfeature to me. It makes sense for a regular expression to give special meanings to backslash sequences, because it's a sublanguage

Re: Raw string substitution problem

2009-12-18 Thread Sion Arrowsmith
Gregory Ewing wrote: >MRAB wrote: >> Regular expressions and replacement strings have their own escaping >> mechanism, which also uses backslashes. >This seems like a misfeature to me. It makes sense for >a regular expression to give special meanings to backslash >sequences, because it's a sublan

Re: Raw string substitution problem

2009-12-17 Thread Gregory Ewing
MRAB wrote: Regular expressions and replacement strings have their own escaping mechanism, which also uses backslashes. This seems like a misfeature to me. It makes sense for a regular expression to give special meanings to backslash sequences, because it's a sublanguage with its own syntax. B

Re: Raw string substitution problem

2009-12-17 Thread Rhodri James
On Thu, 17 Dec 2009 20:18:12 -, Alan G Isaac wrote: So is the bottom line the following? A string replacement is not just "converted" as described in the documentation, essentially it is compiled? That depends entirely on what you mean. But that cannot quite be right. E.g., \b will b

Re: Raw string substitution problem

2009-12-17 Thread MRAB
Alan G Isaac wrote: On 12/17/2009 2:45 PM, MRAB wrote: re.compile('a\\nc') _does_ compile to the same as regex as re.compile('a\nc'). However, regex objects never compare equal to each other, so, strictly speaking, re.compile('a\nc') != re.compile('a\nc'). However, having said that, the re mod

Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac
On 12/17/2009 2:45 PM, MRAB wrote: re.compile('a\\nc') _does_ compile to the same as regex as re.compile('a\nc'). However, regex objects never compare equal to each other, so, strictly speaking, re.compile('a\nc') != re.compile('a\nc'). However, having said that, the re module contains a cache

Re: Raw string substitution problem

2009-12-17 Thread MRAB
Alan G Isaac wrote: Alan G Isaac wrote: >>> re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc', 'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg') True Why are the first two strings being treated as if they are the last one? On 12/17/2009

Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac
Alan G Isaac wrote: >>> re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc', 'a\\nb\\n.c\\a','123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg') True Why are the first two strings being treated as if they are the last one? On 12/17/2009 12:19 PM, D'Arcy J.M.

Re: Raw string substitution problem

2009-12-17 Thread MRAB
Alan G Isaac wrote: On 12/17/2009 11:24 AM, Richard Brodie wrote: A raw string is not a distinct type from an ordinary string in the same way byte strings and Unicode strings are. It is a merely a notation for constants, like writing integers in hexadecimal. (r'\n', u'a', 0x16) ('\\n', u'a',

Re: Raw string substitution problem

2009-12-17 Thread D'Arcy J.M. Cain
On Thu, 17 Dec 2009 11:51:26 -0500 Alan G Isaac wrote: > >>> re.sub('abc', r'a\nb\n.c\a','123abcdefg') == re.sub('abc', > 'a\\nb\\n.c\\a',' 123abcdefg') == re.sub('abc', 'a\nb\n.c\a','123abcdefg') > True Was this a straight cut and paste or did you make a manual change? Is tha

Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac
On 12/17/2009 11:24 AM, Richard Brodie wrote: A raw string is not a distinct type from an ordinary string in the same way byte strings and Unicode strings are. It is a merely a notation for constants, like writing integers in hexadecimal. (r'\n', u'a', 0x16) ('\\n', u'a', 22) Yes, that was

Re: Raw string substitution problem

2009-12-17 Thread Richard Brodie
"Alan G Isaac" wrote in message news:qemdnrut0jvj1lfwnz2dnuvz_vqdn...@rcn.net... > Naturally enough. So I think the right answer is: > > 1. this is a documentation bug (i.e., the documentation >fails to specify unexpected behavior for raw strings), or > 2. this is a bug (i.e., raw strings

Re: Raw string substitution problem

2009-12-17 Thread Alan G Isaac
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith escribió: I am having a problem when substituting a raw string. When I do the following: re.sub('abc', r'a\nb\nc', '123abcdefg') I get """ 123a b cdefg """ what I want is r'123a\nb\ncdefg' On 12/16/2009 9:35 AM, Gabriel Genellina wrote: Fr

Re: Raw string substitution problem

2009-12-16 Thread Ed Keith
--- On Wed, 12/16/09, Peter Otten <__pete...@web.de> wrote: > Another possibility: > > >>> print re.sub('abc', lambda m: r'a\nb\n.c\a', > '123abcdefg') > 123a\nb\n.c\adefg I'm not sure whether that is clever, ugly, or just plain strange! I think I'll stick with: >>> m = re.match('^(.*)abc(.*)

Re: Raw string substitution problem

2009-12-16 Thread Peter Otten
Gabriel Genellina wrote: > En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten <__pete...@web.de> > escribió: > >> Ed Keith wrote: >> >>> --- On Wed, 12/16/09, Gabriel Genellina wrote: >>> Ed Keith escribió: > I am having a problem when substituting a raw string. When I do

Re: Raw string substitution problem

2009-12-16 Thread Gabriel Genellina
En Wed, 16 Dec 2009 14:51:08 -0300, Peter Otten <__pete...@web.de> escribió: Ed Keith wrote: --- On Wed, 12/16/09, Gabriel Genellina wrote: Ed Keith escribió: > I am having a problem when substituting a raw string. When I do the following: > > re.sub('abc', r'a\nb\nc', '123abcdefg') > >

Re: Raw string substitution problem

2009-12-16 Thread Peter Otten
Ed Keith wrote: > --- On Wed, 12/16/09, Gabriel Genellina wrote: > >> From: Gabriel Genellina >> Subject: Re: Raw string substitution problem >> To: python-list@python.org >> Date: Wednesday, December 16, 2009, 9:35 AM >> En Wed, 16 Dec 2009 11:09:32 -0300,

Re: Raw string substitution problem

2009-12-16 Thread Ed Keith
--- On Wed, 12/16/09, Gabriel Genellina wrote: > From: Gabriel Genellina > Subject: Re: Raw string substitution problem > To: python-list@python.org > Date: Wednesday, December 16, 2009, 9:35 AM > En Wed, 16 Dec 2009 11:09:32 -0300, > Ed Keith > escribió: > > &

Re: Raw string substitution problem

2009-12-16 Thread Chris Hulan
On Dec 16, 9:09 am, Ed Keith wrote: > I am having a problem when substituting a raw string. When I do the following: > > re.sub('abc', r'a\nb\nc', '123abcdefg') > > I get > > """ > 123a > b > cdefg > """ > > what I want is > > r'123a\nb\ncdefg' > > How do I get what I want? > > Thanks, > >     -Ed

Re: Raw string substitution problem

2009-12-16 Thread Gabriel Genellina
En Wed, 16 Dec 2009 11:09:32 -0300, Ed Keith escribió: I am having a problem when substituting a raw string. When I do the following: re.sub('abc', r'a\nb\nc', '123abcdefg') I get """ 123a b cdefg """ what I want is r'123a\nb\ncdefg' From http://docs.python.org/library/re.html#re.sub

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

Re: Raw string printing

2007-09-25 Thread Alexandre Badez
On Sep 25, 2:24 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Alexandre Badez wrote: > > I would like to do something like: > > > s = r"a\tb\n" > > print unraw(s) # <= this is the "magic" function I'm searching for > > # result with > > ab > > n > > > Does any of you know how to do it properly ?

Re: Raw string printing

2007-09-25 Thread Peter Otten
Alexandre Badez wrote: > I would like to do something like: > > s = r"a\tb\n" > print unraw(s) # <= this is the "magic" function I'm searching for > # result with > ab > n > > Does any of you know how to do it properly ? >>> print r"a\tb\nx".decode("string-escape") a b x Peter -- h

Re: raw string

2007-09-18 Thread [EMAIL PROTECTED]
On Sep 18, 5:20 am, Konstantinos Pachopoulos <[EMAIL PROTECTED]> wrote: > Hi, > i am trying to execute the following query on a DB: > qe.execQuery(r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY > '"' LINES TERMINATED BY '\n' FROM Commiter") > > However, whether i put the r in the front

Re: raw string

2007-09-18 Thread James Stroud
Konstantinos Pachopoulos wrote: > Hi, > i am trying to execute the following query on a DB: > qe.execQuery(r"SELECT * FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY > '"' LINES TERMINATED BY '\n' FROM Commiter") > > However, whether i put the r in the front or not, i always get an error > about

Re: Raw string fu

2005-11-21 Thread 'Dang' Daniel Griffith
On 26 Oct 2005 12:27:53 -0700, "Paul McGuire" <[EMAIL PROTECTED]> wrote: >"Raw string fu"? A new martial art? For the udon-aware. --dang -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw string fu

2005-10-26 Thread Paul McGuire
"Raw string fu"? A new martial art? -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw string fu

2005-10-26 Thread Fredrik Lundh
Joshua Ginsberg wrote: > >>> r'\' > File "", line 1 > r'\' > ^ > SyntaxError: EOL while scanning single-quoted string > >>> r'\\' > '' > > Does that seem wrong to anybody else? Shouldn't the first one be > syntactically correct? the "r" prefix doesn't change how string literals are parsed; it

Re: Raw string fu

2005-10-26 Thread Jaime Wyant
Doh. that example was supposed to be -> >>> r'I can\'t end strings with a \.' "I can\\'t end strings with a \\." On 10/26/05, Jaime Wyant <[EMAIL PROTECTED]> wrote: > This URL has a good section on raw strings. > > http://www.ferg.org/projects/python_gotchas.html > > r'\' is wrong because raw stri

Re: Raw string fu

2005-10-26 Thread Jaime Wyant
This URL has a good section on raw strings. http://www.ferg.org/projects/python_gotchas.html r'\' is wrong because raw strings were originally added to make regular expressions easier to write. And you can't have a regexp that ends with \. Also, you can use the \ to escape your original quote c