Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 5:19 AM, Ben Bacarisse wrote: > Chris Angelico writes: > >> On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney >> wrote: >>> Travis Griggs writes: >>> Here’s 3 examples: if k + ‘_@‘ in documents: timeKey = k + ‘_@‘ historyKey = th

Re: Concatenating Strings

2015-04-09 Thread Ben Bacarisse
Chris Angelico writes: > On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney > wrote: >> Travis Griggs writes: >> >>> Here’s 3 examples: >>> >>> if k + ‘_@‘ in documents: >>> >>> timeKey = k + ‘_@‘ >>> >>> historyKey = thingID + ‘_’ + k >> >> In addition to the other responses, I'll point

Re: Help with ElementTree

2015-04-09 Thread Larry Martell
On Thu, Apr 9, 2015 at 2:42 PM, Ben Finney wrote: > Larry Martell writes: > >> I have an XML file that looks like this (this is just the pertinent >> part, the file is huge): > > It's also not a very helpful schema. Elements called “Node”, where the > actual type of element is in an attribute, ju

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:46 AM, Ben Finney wrote: > Travis Griggs writes: > >> Here’s 3 examples: >> >> if k + ‘_@‘ in documents: >> >> timeKey = k + ‘_@‘ >> >> historyKey = thingID + ‘_’ + k > > In addition to the other responses, I'll point out a different issue: > > Your client is

Re: Help with ElementTree

2015-04-09 Thread Larry Martell
On Thu, Apr 9, 2015 at 2:39 PM, Peter Otten <__pete...@web.de> wrote: > Larry Martell wrote: > >> I have an XML file that looks like this (this is just the pertinent >> part, the file is huge): >> >> >> >> >> >> >> >> >> KA21 >>

Re: Concatenating Strings

2015-04-09 Thread Ben Finney
Travis Griggs writes: > Here’s 3 examples: > > if k + ‘_@‘ in documents: > > timeKey = k + ‘_@‘ > > historyKey = thingID + ‘_’ + k In addition to the other responses, I'll point out a different issue: Your client is composing messages that munge your text. Ensure you post only the e

Re: Concatenating Strings

2015-04-09 Thread Andrew Farrell
I am under the impression that using format() is the canonically "right way to do it". It is certainly more readable than using ''.join() and is more semantically specific than string addition. On Thu, Apr 9, 2015 at 1:35 PM, Chris Angelico wrote: > On Fri, Apr 10, 2015 at 4:29 AM, Travis Griggs

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:44 AM, Andrew Farrell wrote: > I am under the impression that using format() is the canonically "right way > to do it". It is certainly more readable than using ''.join() and is more > semantically specific than string addition. Depends what you're doing. Sometimes it's

Re: Help with ElementTree

2015-04-09 Thread Ben Finney
Larry Martell writes: > I have an XML file that looks like this (this is just the pertinent > part, the file is huge): It's also not a very helpful schema. Elements called “Node”, where the actual type of element is in an attribute, just make your job needlessly harder. They also pointlessly fo

Re: Help with ElementTree

2015-04-09 Thread Peter Otten
Larry Martell wrote: > I have an XML file that looks like this (this is just the pertinent > part, the file is huge): > > > > > > > > > KA21 > KA21 > > > > > > >

Re: Concatenating Strings

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 4:29 AM, Travis Griggs wrote: > > if k + ‘_@‘ in documents: > > timeKey = k + ‘_@‘ > > historyKey = thingID + ‘_’ + k > > I’m curious where others lean stylistically with this kind of thing. I see > *at least* 2 other alternatives: > So few? I'd just use strin

Concatenating Strings

2015-04-09 Thread Travis Griggs
I was doing some maintenance now on a script of mine… I noticed that I compose strings in this little 54 line file multipole times using the + operator. I was prototyping at the time I wrote it and it was quick and easy. I don’t really care for the way they read. Here’s 3 examples: if k + ‘

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Steven D'Aprano : > It's not so much the undefined behaviour part that gets me. That's bad > enough. But the concept that having the compiler ignore what you write > in the source code because you've accidentally hit some undefined part > of the spec *is a feature* rather than a horrible, horrible

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Chris Angelico : > With applications languages, as earlier mentioned, none of this should > be necessary. Sacrifice the performance and have arbitrary-precision > integers, Unicode strings, garbage collection, and first-class > lists/functions/mappings etc. This is only about lower-level > languag

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Steven D'Aprano : > There are good ways to deal with out-of-range results in systems > languages: > > - well-defined wrap-around behaviour; > - saturation; > - trapping. Some months back I reported a bug in LXDE's CPU monitor applet: after a couple of months of operation, the CPU monitor displaye

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 3:41 AM, Steven D'Aprano wrote: > There are good ways to deal with out-of-range results in systems languages: > > - well-defined wrap-around behaviour; > - saturation; > - trapping. > > "Do whatever the hell the compiler feels like doing" is not one of them. Systems langua

Help with ElementTree

2015-04-09 Thread Larry Martell
I have an XML file that looks like this (this is just the pertinent part, the file is huge): KA21 KA21 00:00:00 15/03/2014 05:56:

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 3:35 AM, Steven D'Aprano wrote: > It's not so much the undefined behaviour part that gets me. That's bad > enough. But the concept that having the compiler ignore what you write in > the source code because you've accidentally hit some undefined part of the > spec *is a fea

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Fri, 10 Apr 2015 02:36 am, Chris Angelico wrote: > *According to the C standard*, you just did something impossible Woo-hoo! I can do the impossible! Immovable objects? I juggle them like rubber balls. Unstoppable forces? I don't even notice them. The very gods themselves will fear me! --

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Chris Angelico : > For low-level bit manipulation work, you usually want an *unsigned* > integer of specific size, with well defined wrap-around behaviour. > When do you actually want a signed integer with well-defined overflow > behaviour? Bit manipulation is not the issue here. The reason for

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Grant Edwards
On 2015-04-09, Chris Angelico wrote: > On Fri, Apr 10, 2015 at 2:53 AM, Grant Edwards > wrote: >> On 2015-04-09, Chris Angelico wrote: >> >>> For application work, it's usually much better to have an integer >>> type like Python's or Pike's int - a signed integer that can never >>> overflow. Fo

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Fri, 10 Apr 2015 02:43 am, Chris Angelico wrote: > For application work, it's usually much better to have an integer type > like Python's or Pike's int - a signed integer that can never > overflow. For low-level bit manipulation work, you usually want an > unsigned integer of specific size, wit

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Fri, 10 Apr 2015 02:25 am, Marko Rauhamaa wrote: > Chris Angelico : > >> As far as it's concerned, it's impossible for a CPU register to >> arbitrarily change without notice. It's equally impossible for the >> addition of two positive signed integers to result in a negative >> integer. > > Th

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Grant Edwards
On 2015-04-09, Chris Angelico wrote: > For application work, it's usually much better to have an integer > type like Python's or Pike's int - a signed integer that can never > overflow. For low-level bit manipulation work, you usually want an > *unsigned* integer of specific size, with well defin

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 2:53 AM, Grant Edwards wrote: > On 2015-04-09, Chris Angelico wrote: > >> For application work, it's usually much better to have an integer >> type like Python's or Pike's int - a signed integer that can never >> overflow. For low-level bit manipulation work, you usually w

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 2:25 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> As far as it's concerned, it's impossible for a CPU register to >> arbitrarily change without notice. It's equally impossible for the >> addition of two positive signed integers to result in a negative >> integer. > > T

Re: Best search algorithm to find condition within a range

2015-04-09 Thread MRAB
On 2015-04-09 16:21, Steven D'Aprano wrote: On Fri, 10 Apr 2015 01:02 am, Chris Angelico wrote: On Fri, Apr 10, 2015 at 12:53 AM, Alain Ketterlin wrote: Ouch, you're right, I tried to stick with Marko's example and forgot the basics. I meant "signed ints", but the "removable" condition should

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 2:15 AM, Steven D'Aprano wrote: > On Fri, 10 Apr 2015 01:34 am, Chris Angelico wrote: > >> It's equally impossible for the addition of two positive signed >> integers to result in a negative integer. > > Why oh why do C programmers tell such porkies??? *semi-wink* > > [stev

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Ian Kelly
On Thu, Apr 9, 2015 at 9:21 AM, wrote: > And i know for a fact What do you know for a fact? > (i've factored RSA in the 200 digit range on a 486 in a couple of hours 98-) Bullshit. RSA-200 wasn't factored until 2005, and the group that did it required three months on a cluster of 80 2.2-GHz Op

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Chris Angelico : > As far as it's concerned, it's impossible for a CPU register to > arbitrarily change without notice. It's equally impossible for the > addition of two positive signed integers to result in a negative > integer. The standard says that any program that takes a signed integer out

Re: [SerialConnection] Help

2015-04-09 Thread Grant Edwards
On 2015-04-09, Travis Griggs wrote: > >> On Apr 7, 2015, at 8:42 AM, Hugo Caldas wrote: >> >> read and write the port values with multi threading > > Care to elaborate what you mean by this part? In general, serial > ports and multi threading don’t mix well. IOW, you’ll need to use > multithre

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Fri, 10 Apr 2015 01:34 am, Chris Angelico wrote: > It's equally impossible for the addition of two positive signed > integers to result in a negative integer. Why oh why do C programmers tell such porkies??? *semi-wink* [steve@ando c]$ gcc add.c [steve@ando c]$ ./a.out a = 1 b = 2147483647 a+

Re: MicroPython 1.4.1 released

2015-04-09 Thread Travis Griggs
> On Apr 4, 2015, at 4:43 PM, Damien George wrote: > > Hello everyone, > > We are pleased to announce the release of MicroPython version 1.4.1! > > MicroPython is an implementation of Python 3.4 which is optimised for > systems with minimal resources, including microcontrollers. > > Since our

Re: [SerialConnection] Help

2015-04-09 Thread Travis Griggs
> On Apr 7, 2015, at 8:42 AM, Hugo Caldas wrote: > > read and write the port values with multi threading Care to elaborate what you mean by this part? In general, serial ports and multi threading don’t mix well. IOW, you’ll need to use multithreading pieces to make sure you serialize your a

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 1:21 AM, Steven D'Aprano wrote: > On Fri, 10 Apr 2015 01:02 am, Chris Angelico wrote: > >> On Fri, Apr 10, 2015 at 12:53 AM, Alain Ketterlin >> wrote: >>> Ouch, you're right, I tried to stick with Marko's example and forgot the >>> basics. I meant "signed ints", but the "r

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 1:11 AM, Steven D'Aprano wrote: > On Thu, 9 Apr 2015 11:33 pm, Marko Rauhamaa wrote: > >> In this day and age, heavily optimized compilers (including gcc) >> actively exploit undefined behavior in code generation. > > Optimization and undefined behaviour reminds me of a sto

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Fri, 10 Apr 2015 01:02 am, Chris Angelico wrote: > On Fri, Apr 10, 2015 at 12:53 AM, Alain Ketterlin > wrote: >> Ouch, you're right, I tried to stick with Marko's example and forgot the >> basics. I meant "signed ints", but the "removable" condition should be >> something like: >> >> if (

Re: Best search algorithm to find condition within a range

2015-04-09 Thread jonas . thornvall
Den torsdag 9 april 2015 kl. 17:04:53 UTC+2 skrev Ian: > On Thu, Apr 9, 2015 at 8:54 AM, wrote: > > Aside from the base changer i've written a bignumb anybase generic > > multiplication, addition and subtraction routine. My goal is to make the > > arithmetic in the base of choice whatever size.

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Steven D'Aprano
On Thu, 9 Apr 2015 11:33 pm, Marko Rauhamaa wrote: > In this day and age, heavily optimized compilers (including gcc) > actively exploit undefined behavior in code generation. Optimization and undefined behaviour reminds me of a story my wife told me, of a time she was crossing the US with some r

Re: Best search algorithm to find condition within a range

2015-04-09 Thread jonas . thornvall
Den torsdag 9 april 2015 kl. 17:02:24 UTC+2 skrev Chris Angelico: > On Fri, Apr 10, 2015 at 12:53 AM, Alain Ketterlin > wrote: > > Ouch, you're right, I tried to stick with Marko's example and forgot the > > basics. I meant "signed ints", but the "removable" condition should be > > something like:

Re: Exception Handling

2015-04-09 Thread Steven D'Aprano
On Thu, 9 Apr 2015 07:31 pm, Palpandi wrote: > Hi all, > > Is there any way to roll back or undo changes which are all done before > exception occurs. Not automatically. You have to program it yourself. -- Steven -- https://mail.python.org/mailman/listinfo/python-list

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Ian Kelly
On Thu, Apr 9, 2015 at 8:54 AM, wrote: > Aside from the base changer i've written a bignumb anybase generic > multiplication, addition and subtraction routine. My goal is to make the > arithmetic in the base of choice whatever size. > > And i think i can do it, i already have mult, add , subt w

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Fri, Apr 10, 2015 at 12:53 AM, Alain Ketterlin wrote: > Ouch, you're right, I tried to stick with Marko's example and forgot the > basics. I meant "signed ints", but the "removable" condition should be > something like: > > if ( x>0 && y>0 && z ... > > i.e., some condition that is n

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Chris Angelico writes: > On Thu, Apr 9, 2015 at 11:57 PM, Alain Ketterlin > wrote: >> Because, in: >> >> z = x+y; // all signed ints >> if ( z < x ) >> ... >> >> either there was no overflow (and the condition is false), or there was, >> and the result is undefined, i.e., "z > Do

Re: Best search algorithm to find condition within a range

2015-04-09 Thread jonas . thornvall
Den torsdag 9 april 2015 kl. 16:08:48 UTC+2 skrev Chris Angelico: > On Thu, Apr 9, 2015 at 11:57 PM, Alain Ketterlin > wrote: > > Because, in: > > > > z = x+y; // all signed ints > > if ( z < x ) > > ... > > > > either there was no overflow (and the condition is false), or there wa

Re: How to convert .doc file to .txt in Python

2015-04-09 Thread subhabrata . banerji
On Thursday, April 9, 2015 at 4:23:55 PM UTC+5:30, Tim Golden wrote: > On 09/04/2015 11:25, wrote: > > Dear Group, > > > > I was trying to convert .doc file to .txt file. > > > > I got of python-docx, zipfile but they do not seem to help me much. > > > > You may kindly suggest how to convert fro

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Chris Angelico
On Thu, Apr 9, 2015 at 11:57 PM, Alain Ketterlin wrote: > Because, in: > > z = x+y; // all signed ints > if ( z < x ) > ... > > either there was no overflow (and the condition is false), or there was, > and the result is undefined, i.e., "zhttps://mail.python.org/mailman/listinfo/p

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > Dave Angel : > >> So the C standard can specify such things as undefined. The >> architecture still will do something specific, right or wrong, and >> that's what Marko's claim was about. The C compiler has separate types >> for unsigned and for signed, while the underlyi

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Marko Rauhamaa : > In this day and age, heavily optimized compilers (including gcc) > actively exploit undefined behavior in code generation. Example: Find the value of INT_MAX programmatically. #include int main() {

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Dave Angel : > So the C standard can specify such things as undefined. The > architecture still will do something specific, right or wrong, and > that's what Marko's claim was about. The C compiler has separate types > for unsigned and for signed, while the underlying architecture of > every twos

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Alain Ketterlin : > Marko Rauhamaa writes: > >> Alain Ketterlin : >> >>> No, it would not work for signed integers (i.e., with lo and hi of >>> int64_t type), because overflow is undefined behavior for signed. >> >> All architectures I've ever had dealings with have used 2's-complement >> integer

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Dave Angel
On 04/09/2015 08:56 AM, Alain Ketterlin wrote: Marko Rauhamaa writes: Alain Ketterlin : No, it would not work for signed integers (i.e., with lo and hi of int64_t type), because overflow is undefined behavior for signed. All architectures I've ever had dealings with have used 2's-complemen

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > Alain Ketterlin : > >> No, it would not work for signed integers (i.e., with lo and hi of >> int64_t type), because overflow is undefined behavior for signed. > > All architectures I've ever had dealings with have used 2's-complement > integers. Overflow is well-defined,

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
Alain Ketterlin : > No, it would not work for signed integers (i.e., with lo and hi of > int64_t type), because overflow is undefined behavior for signed. All architectures I've ever had dealings with have used 2's-complement integers. Overflow is well-defined, well-behaved and sign-independent w

Re: python implementation of a new integer encoding algorithm.

2015-04-09 Thread Dave Angel
On 04/09/2015 05:33 AM, janhein.vanderb...@gmail.com wrote: Op donderdag 19 februari 2015 19:25:14 UTC+1 schreef Dave Angel: I wrote the following pair of functions: Here's a couple of ranges of output, showing that the 7bit scheme does better for values between 384 and 16379. Thanks fo

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Alain Ketterlin
Marko Rauhamaa writes: > The basic arithmetic algorithms are independent of the base. Right. > For example, here's how you can add two 128-bit integers in C using > 64-bit digits: > > typedef struct { > uint64_t lo, hi; > } uint128_t; > > uint128_t add128(uint128_t x, uint12

Re: How to convert .doc file to .txt in Python

2015-04-09 Thread Tim Chase
On 2015-04-09 03:25, subhabrata.bane...@gmail.com wrote: > You may kindly suggest how to convert from .doc > to .docx/.html/.pdf/.rtf as from them I am being able to convert > to .txt. Use an external tool such as "wv", "antiword", or "catdoc" that has already done the hard work for you. -tkc

Re: How to convert .doc file to .txt in Python

2015-04-09 Thread subhabrata . banerji
On Thursday, April 9, 2015 at 3:56:09 PM UTC+5:30, subhabrat...@gmail.com wrote: > Dear Group, > > I was trying to convert .doc file to .txt file. > > I got of python-docx, zipfile but they do not seem to help me much. > > You may kindly suggest how to convert from .doc to .docx/.html/.pdf/.rt

Re: How to convert .doc file to .txt in Python

2015-04-09 Thread Tim Golden
On 09/04/2015 11:25, subhabrata.bane...@gmail.com wrote: > Dear Group, > > I was trying to convert .doc file to .txt file. > > I got of python-docx, zipfile but they do not seem to help me much. > > You may kindly suggest how to convert from .doc to > .docx/.html/.pdf/.rtf as from them I am bein

Re: Exception Handling

2015-04-09 Thread Chris Angelico
On Thu, Apr 9, 2015 at 7:31 PM, Palpandi wrote: > Hi all, > > Is there any way to roll back or undo changes which are all done before > exception occurs. In Python itself? Not directly; there are no facilities for undoing Python code. But if you're serious about integrity, you probably want to b

How to convert .doc file to .txt in Python

2015-04-09 Thread subhabrata . banerji
Dear Group, I was trying to convert .doc file to .txt file. I got of python-docx, zipfile but they do not seem to help me much. You may kindly suggest how to convert from .doc to .docx/.html/.pdf/.rtf as from them I am being able to convert to .txt. If any one of the Python experts may kind

Re: Code critique please

2015-04-09 Thread Peter Otten
kai.pet...@gmail.com wrote: > I just wrote this bit (coming from Pascal) > if (((xdim / 8) * ydim) + header) <> filesize: Yeah, either Pascal or Barry Warsaw is your uncle ;) https://www.python.org/dev/peps/pep-0401/ > and am wondering how seasoned > Python programmers would have done the

Re: Best search algorithm to find condition within a range

2015-04-09 Thread Marko Rauhamaa
BartC : > On 08/04/2015 23:06, Marko Rauhamaa wrote: >> Arithmetics is performed just like in elementary school. > > Not in the school I went to; we used decimal! The basic arithmetic algorithms are independent of the base. For example, here's how you can add two 128-bit integers in C using 64-b

Re: python implementation of a new integer encoding algorithm.

2015-04-09 Thread janhein . vanderburg
Op donderdag 19 februari 2015 19:25:14 UTC+1 schreef Dave Angel: > I wrote the following pair of functions: > > def seven_code(n): > acc = bytearray() > if n == 0: > acc.append(0) > while n > 0: > quotient, remainder = divmod(n, 128) > acc.append(remainder

Exception Handling

2015-04-09 Thread Palpandi
Hi all, Is there any way to roll back or undo changes which are all done before exception occurs. -- https://mail.python.org/mailman/listinfo/python-list

Re: Best search algorithm to find condition within a range

2015-04-09 Thread BartC
On 08/04/2015 23:06, Marko Rauhamaa wrote: BartC : So the the number 3,012,345, in base 100, could represented in text form as the two 'digit': (3, 12345) ie. 3*100 + 12345*1. In internal binary, each digit can just be stored in the normal form, probably as one digit per 32-bit inte

Re: python implementation of a new integer encoding algorithm.

2015-04-09 Thread janhein . vanderburg
Op donderdag 19 februari 2015 19:05:12 UTC+1 schreef Ian: > That stop-bit variant looks extremely inefficient (and wrong) to me. You are right; I was wrong. > encoding with just a small amount of binary at the end. This is what I > would expect a 2-bit stop-bit encoding to look like: > > 0: 00 >

Re: How to find out which named regular expression group corresponds to which positional regex group

2015-04-09 Thread Serhiy Storchaka
On 08.04.15 16:23, Mattias Ugelvik wrote: I'm making a string manipulation tool in which I need to know this correlation. Take this example: re.match('(?Pa?)(?Pb?)', '') I need to know that 'first' is group #1, and 'second' is group #2. I need this to resolve certain ambiguities. I was hopin

Re: Proposal for new minor syntax

2015-04-09 Thread Antoon Pardon
On 03/28/2015 11:43 AM, Steven D'Aprano wrote: > On Sat, 28 Mar 2015 08:53 pm, Steven D'Aprano wrote: > > >> It saves typing. It might even allow a micro-optimization in the generated >> bytecode (see below). > Oops, I forgot to include the "see below" bit. > > Comparing > > a = a.spam() > > a .=

Re: Get nesting of regex groups

2015-04-09 Thread Mattias Ugelvik
(sorry if I'm spamming the mailing list, my reply didn't seem to show up in the archive) I'm making a 'declarative string manipulation' tool, the interface of which should work like this: >>> rules(r'(?P(?Pa?))(?Pb?)', { ... 'separate': '.suffix', ... 'inner': 'abc', ... 'outer': lambda str

Re: Get nesting of regex groups

2015-04-09 Thread Mattias Ugelvik
I'm making a 'declarative string manipulation' tool, the interface of which should work like this: >>> rules(r'(?P(?Pa?))(?Pb?)', { ... 'separate': '.suffix', ... 'inner': 'abc', ... 'outer': lambda string: 'some-{}-manipulation'.format(string) ... }).apply('a') 'some-abc-manipulation.suffix