Re: [Python-ideas] A cute Python implementation of itertools.tee

2018-04-16 Thread Koos Zevenhoven
On Mon, Apr 16, 2018 at 12:06 AM, Tim Peters wrote: > [Koos Zevenhoven ] > > It's definitely possible to write the above in a more > > readable way, and FWIW I don't think it involves "assignments as > > expressions". > > Of course it is. The point was brevity and speed, not readability. > I

Re: [Python-ideas] A cute Python implementation of itertools.tee

2018-04-16 Thread Koos Zevenhoven
On Sun, Apr 15, 2018 at 11:55 PM, Chris Angelico wrote: > On Mon, Apr 16, 2018 at 6:46 AM, Koos Zevenhoven > wrote: > > Anyway, the whole linked list is unnecessary if the iterable can be > iterated > > over multiple times. But "tee" won't know when to do that. *That* is > what I > > call overhe

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-16 Thread Steven D'Aprano
On Mon, Apr 16, 2018 at 05:22:54AM +, Steve Barnes wrote: > Wouldn't it make sense to have the current counter behaviour, (negative > counts not allowed), and also a counter that did allow negative values > (my bank doesn't seem to have a problem with my balance being able to go > below neg

Re: [Python-ideas] A cute Python implementation of itertools.tee

2018-04-16 Thread Steven D'Aprano
On Sun, Apr 15, 2018 at 08:35:51PM +0300, Serhiy Storchaka wrote: > I have ideas about implementing zero-overhead try/except, but I have > doubts that it is worth. The benefit seems too small. It is conventional wisdom that catching exceptions is expensive, and that in performance critical code

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Kirill Balunov
2018-04-15 23:22 GMT+03:00 Chris Angelico : > > > 0. > > > > while (items[i := i+1] := read_next_item()) is not None: > > print(r'%d/%d' % (i, len(items)), end='\r') > > > > 1. > > > > while (read_next_item() -> items[(i+1) -> i]) is not None: > > print(r'%d/%d' % (i, len(items)), end='\r'

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
В Воскресенье, 15 апр. 2018 в 6:19 , Oleg Broytman написал: Can I recommend to catch exceptions in `backuper.backup()`, cleanup backuper and unlock locker? Yes, thanks, I move .backup() to try, about other exception I think that it must be catched outside, because this module don't know that

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
В Воскресенье, 15 апр. 2018 в 10:47 , George Fischhof написал: https://docs.python.org/3/library/fileinput.html Thanks, it works https://github.com/worldmind/scripts/blob/master/filerewrite/fileinputtest.py but looks like that way only for line by line processing _

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
В Воскресенье, 15 апр. 2018 в 1:12 , Serhiy Storchaka написал: Actually the reliable code should write into a separate file and replace the original file by the new file only if writing is successful. Or backup the old file and restore it if writing is failed. Or do both. And handle hard and s

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
В Воскресенье, 15 апр. 2018 в 10:47 , George Fischhof написал: https://docs.python.org/3/library/fileinput.html https://pypi.python.org/pypi/in-place looks not bad too ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mail

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
В Понедельник, 16 апр. 2018 в 2:48 , Alexey Shrub написал: https://pypi.python.org/pypi/in-place I like in_place module https://github.com/worldmind/scripts/blob/master/filerewrite/inplacetest.py it fix some strange features of fileinput module. Maybe in_place must be in standard library inste

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Kirill Balunov
[Guido] 2018-04-15 20:19 GMT+03:00 Guido van Rossum : > On Sun, Apr 15, 2018 at 4:05 AM, Kirill Balunov > wrote: > >> [...] For me personally, `: =` looks and feels just like normal >> assignment statement which can be used interchangeable but in many more >> places in the code. And if the main

Re: [Python-ideas] Rewriting file - pythonic way

2018-04-16 Thread Alexey Shrub
https://pypi.python.org/pypi/in-place > * Instead of hijacking sys.stdout, a new filehandle is returned for writing. > * The filehandle supports all of the standard I/O methods, not just readline(). why fileinput did not support this things? ___ Pyt

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Mikhail V
On Sun, Apr 15, 2018 at 6:58 PM, Steven D'Aprano wrote: > On Sun, Apr 15, 2018 at 10:21:02PM +1000, Chris Angelico wrote: > >> I don't think we're ever going to unify everyone on an arbitrary >> question of "expression first" or "name first". But to all the >> "expression first" people, a question

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-16 Thread Peter O'Connor
Hi Danilo, The idea of decorating a function to show that the return variables could be fed back in in a scan form is interesting and could solve my problem in a nice way without new syntax. I looked at your code but got a bit confused as to how it works (there seems to be some magic where the de

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-16 Thread Peter O'Connor
In any case, although I find the magic variable-injection stuff quite strange, I like the decorator. Something like @scannable(average=0) # Wrap function so that it has a "scan" method which can be used to generate a stateful scan object def exponential_moving_average(average, x, decay):

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Steven D'Aprano
On Mon, Apr 16, 2018 at 06:16:46AM +1000, Chris Angelico wrote: [...] > >> >>> items = [None] * 10 > >> >>> i = -1 > >> >>> items[i := i + 1] = input("> ") > >> > asdf > >> >>> items[i := i + 1] = input("> ") > >> > qwer > >> >>> items[i := i + 1] = input("> ") > >> > zxcv > >> >>> > >> >>> items

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-16 Thread Tim Peters
[Steve Barnes ] > Wouldn't it make sense to have the current counter behaviour, (negative > counts not allowed), and also a counter that did allow negative values > (my bank doesn't seem to have a problem with my balance being able to go > below negative), and possibly at the same time a counter cl

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Nick Coghlan
On 16 April 2018 at 03:45, Steve Barnes wrote: > On 15/04/2018 08:12, Nick Coghlan wrote: >> The discoverability of these kinds of techniques could definitely >> stand to be improved, but the benefit of adopting them is that they >> work on all currently supported versions of Python (even >> impor

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Nick Coghlan
On 16 April 2018 at 00:27, Thautwarm Zhao wrote: > Personally I prefer "as", but I think without a big change of python Grammar > file, it's impossible to avoid parsing "with expr as name" into "with (expr > as name)" because "expr as name" is actually an "expr". > I have mentioned this in previou

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Paul Moore
On 16 April 2018 at 17:22, Nick Coghlan wrote: > If we're not covering explicit __path__ manipulation anywhere, we > should definitely mention that possibility. > https://docs.python.org/3/library/pkgutil.html#pkgutil.extend_path > does talk about it, but only in the context of scanning sys.path f

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Eric Fahlgren
The documentation is pretty opaque or non-existent on other aspects of importlib use, too. If I enable warnings, I see this (and many more like it). I've read PEP 302 a couple times, read the code in importlib that detects the warning and searched down several rabbit holes, only to come up empty.

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Brett Cannon
On Mon, 16 Apr 2018 at 09:58 Eric Fahlgren wrote: > The documentation is pretty opaque or non-existent on other aspects of > importlib use, too. > Well, we are diving into the dark corners of import here. (Details can be found in the language reference: https://docs.python.org/3/reference/import

Re: [Python-ideas] Move optional data out of pyc files

2018-04-16 Thread Brett Cannon
On Sat, 14 Apr 2018 at 17:01 Neil Schemenauer wrote: > On 2018-04-12, M.-A. Lemburg wrote: > > This leaves the proposal to restructure pyc files into a sectioned > > file and possibly indexed file to make access to (lazily) loaded > > parts faster. > > I would like to see a format can hold one or

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Chris Angelico
On Tue, Apr 17, 2018 at 1:54 AM, Steven D'Aprano wrote: > On Mon, Apr 16, 2018 at 06:16:46AM +1000, Chris Angelico wrote: > [...] > >> >> >>> items = [None] * 10 >> >> >>> i = -1 >> >> >>> items[i := i + 1] = input("> ") >> >> > asdf >> >> >>> items[i := i + 1] = input("> ") >> >> > qwer >> >> >>>

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Chris Angelico
On Mon, Apr 16, 2018 at 11:05 PM, Mikhail V wrote: > Lets just return to some of proposed examples > (I use "=" in both examples to be less biased here): > > 1. > if ( match = re.match("foo", S) ) == True: > print("match:", match) > > 2. > if ( re.match("foo", S) = match ) == True: > pri

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Ethan Furman
On 04/16/2018 10:36 AM, Chris Angelico wrote: Not after it got trimmed, no. Here's what I actually said in my original post: while (read_next_item() -> items[i + 1 -> i]) is not None: print("%d/%d..." % (i, len(items)), end="\r") Now, if THAT is your assignment target, are you still as ha

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Ned Batchelder
On 4/16/18 1:42 PM, Chris Angelico wrote: 3) "expr -> name" ==> The information went data way. So either you take a parallel from elsewhere in Python syntax, or you take a hopefully-intuitive dataflow mnemonic symbol. Take your pick. My problem with the "->" option is that function annotations

Re: [Python-ideas] Idea: Importing from arbitrary filenames

2018-04-16 Thread Eric Fahlgren
On Mon, Apr 16, 2018 at 10:23 AM, Brett Cannon wrote: > > > On Mon, 16 Apr 2018 at 09:58 Eric Fahlgren wrote: > >> The documentation is pretty opaque or non-existent on other aspects of >> importlib use, too. >> > > Well, we are diving into the dark corners of import here. (Details can be > foun

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Steve Barnes
> Here are the three most popular syntax options, and how each would be > explained: > > 1) "target := expr" ==> It's exactly the same as other forms of > assignment, only now it's an expression. > 2) "expr as name" ==> It's exactly the same as other uses of "as", > only now it's just grabbing t

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Chris Angelico
On Tue, Apr 17, 2018 at 5:11 AM, Steve Barnes wrote: > >> Here are the three most popular syntax options, and how each would be >> explained: >> >> 1) "target := expr" ==> It's exactly the same as other forms of >> assignment, only now it's an expression. >> 2) "expr as name" ==> It's exactly the

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Mikhail V
On Mon, Apr 16, 2018 at 8:42 PM, Chris Angelico wrote: > On Mon, Apr 16, 2018 at 11:05 PM, Mikhail V wrote: > > Here are the three most popular syntax options, and how each would be > explained: > > 1) "target := expr" ==> It's exactly the same as other forms of > assignment, only now it's an ex

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Chris Angelico
On Tue, Apr 17, 2018 at 5:42 AM, Mikhail V wrote: > On Mon, Apr 16, 2018 at 8:42 PM, Chris Angelico wrote: >> On Mon, Apr 16, 2018 at 11:05 PM, Mikhail V wrote: >> >> Here are the three most popular syntax options, and how each would be >> explained: >> >> 1) "target := expr" ==> It's exactly t

Re: [Python-ideas] Proposal: A Reduce-Map Comprehension and a "last" builtin

2018-04-16 Thread Danilo J. S. Bellini
On 16 April 2018 at 10:49, Peter O'Connor wrote: > Are you able to show how you'd implement the moving average example with > your package? > Sure! The single pole IIR filter you've shown is implemented here: https://github.com/danilobellini/pyscanprev/blob/master/examples/iir-filter.rst I trie

Re: [Python-ideas] collections.Counter should implement __mul__, __rmul__

2018-04-16 Thread Tim Peters
[Tim] >> I also have no problem with inplace operators. Or with adding >> `Counter /= scalar", for that matter. [Raymond] > But surely __rdiv__() would be over the top, harmonic means be damned ;-) Agreed - itertools.Counter is the poster child for "practicality beats purity" :-) In context, th

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Gregory P. Smith
On Mon, Apr 16, 2018 at 11:11 AM Ned Batchelder wrote: > On 4/16/18 1:42 PM, Chris Angelico wrote: > > 3) "expr -> name" ==> The information went data way. > > > > So either you take a parallel from elsewhere in Python syntax, or you > > take a hopefully-intuitive dataflow mnemonic symbol. Take y

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Thautwarm Zhao
> We have ways of cheating a bit if we want to reinterpret the semantics > of something that nevertheless parses cleanly - while the parser is > limited to single token lookahead, it's straightforward for the > subsequent code generation stage to look a single level down in the > parse tree and se

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-16 Thread Ethan Furman
On 04/10/2018 10:32 PM, Chris Angelico wrote: PEP: 572 Title: Assignment Expressions Author: Chris Angelico Chris, I think you've gotten all the feedback you need. Pick a symbol (I'd say either ":=" or "as"), and slap this puppy over onto python-dev. -- ~Ethan~ ___

Re: [Python-ideas] Spelling of Assignment Expressions PEP 572 (was post #4)

2018-04-16 Thread Guido van Rossum
On Mon, Apr 16, 2018 at 8:09 PM, Thautwarm Zhao wrote: > > > 3) "target ? expr" (where ? is some other word/character - IIRC > > "target from expr" was proposed once) > > A more popular convention is to mark `?` as handling boolean variables, so > `target ? expr` could mean `expr if target els

Re: [Python-ideas] PEP 572: Assignment Expressions (post #4)

2018-04-16 Thread Chris Angelico
On Tue, Apr 17, 2018 at 1:54 PM, Ethan Furman wrote: > On 04/10/2018 10:32 PM, Chris Angelico wrote: > >> PEP: 572 >> Title: Assignment Expressions >> Author: Chris Angelico > > > Chris, I think you've gotten all the feedback you need. Pick a symbol (I'd > say either ":=" or "as"), and slap this

[Python-ideas] Providing a public API for creating and parsing HTTP messages

2018-04-16 Thread Derek Maciel
Hello all, If this is not the appropriate place for this type of proposal please let me know. The modules http.client and http.server both do a wonderful job when implementing HTTP clients and servers, respectively. However, occasionally there may be a need to create and parse HTTP messages thems