Re: Iterator addition

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 17:28:59 -0600, [EMAIL PROTECTED] wrote: [...] > >On Sun, Nov 13, 2005 at 09:44:43PM +, Bengt Richter wrote: >> even if expr1 had a __unaryop__ method, >> expr1 - expr2 >> could not become >> expr1.__unaryop__(-expr2) >> unless you forced the issue with >> expr1

Re: Iterator addition

2005-11-13 Thread jepler
On Sun, Nov 13, 2005 at 09:44:43PM +, Bengt Richter wrote: > even if expr1 had a __unaryop__ method, > expr1 - expr2 > could not become > expr1.__unaryop__(-expr2) > unless you forced the issue with > expr1 (-expr2) as opposed to being a function call? I don't think you've solved

Re: Iterator addition

2005-11-13 Thread Bengt Richter
On Sun, 13 Nov 2005 17:31:32 +0100, Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: >> Tom Anderson: >>> And we're halfway to looking like perl already! Perhaps a more pythonic >>> thing would be to define a "then" operator: >>> all_lines = file1 then file2 then file3 >>

Re: Iterator addition

2005-11-13 Thread Tom Anderson
On Sun, 13 Nov 2005, Reinhold Birkenfeld wrote: > [EMAIL PROTECTED] wrote: > >> Tom Anderson: > >>> And we're halfway to looking like perl already! Perhaps a more >>> pythonic thing would be to define a "then" operator: >>> >>> all_lines = file1 then file2 then file3 >> >> Or a "chain" one: >> >>

Re: Iterator addition

2005-11-13 Thread Reinhold Birkenfeld
[EMAIL PROTECTED] wrote: > Tom Anderson: >> And we're halfway to looking like perl already! Perhaps a more pythonic >> thing would be to define a "then" operator: >> all_lines = file1 then file2 then file3 > > Or a "chain" one: >> all_lines = file1 chain file2 chain file3 That's certainly not bet

Re: Iterator addition

2005-11-12 Thread bearophileHUGS
Tom Anderson: > And we're halfway to looking like perl already! Perhaps a more pythonic > thing would be to define a "then" operator: > all_lines = file1 then file2 then file3 Or a "chain" one: > all_lines = file1 chain file2 chain file3 Bearophile -- http://mail.python.org/mailman/listinfo/pyt

Re: Iterator addition

2005-11-12 Thread Tom Anderson
not so sure. > > Hmm, there might also be __add__ operations on the objects, that would > have to take precedence over iterator addition. Iterator addition > itself would have to be a special kludge like figuring out "<" from > __cmp__, etc. > > Yeah, I guess

Re: Iterator addition

2005-11-09 Thread Paul Rubin
I mistakenly try to add a list to a dict, I get an > exception which immediately alerts me to my mistake. I definitely > wouldn't want to lose that... Hmm, there might also be __add__ operations on the objects, that would have to take precedence over iterator addition. Iterator additi

Re: Iterator addition

2005-11-09 Thread Alex Martelli
Paul Rubin wrote: > Is there a good reason to not define iter1+iter2 to be the same as > itertools.chain(iter1, iter2)? No -- feel free to define __add__ accordingly in every one of your iterator classes. If you mean for *ALL* built-in types, such as generators, lists,

Iterator addition

2005-11-09 Thread Paul Rubin
Is there a good reason to not define iter1+iter2 to be the same as itertools.chain(iter1, iter2)? Examples: # all lines in a collection of files, like perl <> all_lines = file1 + file2 + file3 candidate_primes = (2,) + (1+2*i for i in itertools.count(1)) # candidate_primes is 2,3,5,7