Re: [Python-ideas] Easily remove characters from a string.

2016-10-25 Thread Sjoerd Job Postmus
On Mon, Oct 24, 2016 at 05:37:29PM -0700, Chris Barker - NOAA Federal wrote: > > On Oct 24, 2016, at 3:54 PM, Chris Angelico wrote: > > > . But in any case, > > this is a question you can't even ask until replace() accepts multiple > > arguments. Hence I'm +1 on the notion of simultaneous replace

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Danilo J. S. Bellini
> > As a practicing economist, I wonder what use cases you're referring > to. I can't think of any use cases where if one previous value is > useful, having all previous values available (ie, an arbitrary > temporal structure, at the modeler's option) isn't vastly more useful. > Well, see the ite

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Neil Girdhar
I was thinking of posting something like the first suggestion myself. Both would be a great additions. On Monday, October 24, 2016 at 6:10:52 PM UTC-4, Ryan Gonzalez wrote: > > I personally find it kind of annoying when you have code like this: > > > x = A(1, B(2, 3)) > > > and Python's error me

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Nick Coghlan
On 25 October 2016 at 03:16, Chris Barker wrote: > On Sat, Oct 22, 2016 at 9:17 AM, Nick Coghlan wrote: > >> >> This is actually a case where style guidelines would ideally differ >> between between scripting use cases ... and >> library(/framework/application) development use cases > > > Hmm --

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Neil Girdhar
Also, for something like this: In [1]: class A: ...: pass ...: In [2]: A(x=2) --- TypeError Traceback (most recent call last) in () > 1 A(x=2) TypeError: object() takes no param

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Nick Coghlan
On 25 October 2016 at 03:32, Chris Barker wrote: > On Sat, Oct 22, 2016 at 8:22 PM, Nick Coghlan wrote: >> The big refactoring benefit that this feature would offer over with >> statements is that it doesn't require a structural change to the code >> - it's just wrapping an existing expression in

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Nick Coghlan
On 25 October 2016 at 11:59, Stephen J. Turnbull wrote: > On the semantic side, > constructs like closures and generators (which they may be cargo- > culting!) mean that it's harder to link resource management to > (syntactic) function calls than a new developer might think. (Isn't > that Nathani

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Michel Desmoulin
Thos are great idea. I love the current trend of trying to give better error messages. Another pet peave of mine: TypeError not providing at least 'raiser' 'accepted type', 'given value' and 'given value type'. E.G, int() does an ok job: >>> int(foo) ValueError: invalid literal for

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Chris Angelico
On Wed, Oct 26, 2016 at 12:20 AM, Michel Desmoulin wrote: > list, set and tuple less not as good: > > >>> tuple(foo) > > TypeError: 'int' object is not iterable > > No raiser, no value given. It's hard to find out what's the problem is. The > biggest issue here is that if you have a long l

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Stephen J. Turnbull
Danilo J. S. Bellini writes: No attribution. Please attribute, at least when you mix quotes from different people. > > As a practicing economist, I wonder what use cases you're referring > > to. I can't think of any use cases where if one previous value is > > useful, having all previous val

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Nick Coghlan
On 25 October 2016 at 23:20, Michel Desmoulin wrote: > Should we make a PEP with all of those ? No, incrementally improving error messages doesn't require PEP level advocacy - it just requires folks doing the development and review work of updating them without breaking anything, and adjusting th

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Paul Moore
On 25 October 2016 at 15:02, Stephen J. Turnbull wrote: > I did. They are very persuasive ... up to the point where you ask for > syntax for something that appears (now that you've done it, kudos!) to > be perfectly do-able with a function. This is an important point by the way. Ideas on this li

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2016 at 05:18:46AM -0200, Danilo J. S. Bellini wrote: > > [...]. From what > > I remember, the conclusion reached was that there are too > > many degrees of freedom to be able to express reduction > > operations in a comprehension-like way that's any clearer Danilo, if you are goi

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-25 Thread Mikhail V
On 25 October 2016 at 04:37, Steven D'Aprano wrote: >> I would be happy to see a somewhat more general and user friendly >> version of string.translate function. >> It could work this way: >> string.newtranslate(file_with_table, Drop=True, Dec=True) > Mikhail, I appreciate that you have many ide

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Yury Selivanov
On 2016-10-25 4:33 AM, Nick Coghlan wrote: I'm starting to think that we instead need a way to let them easily say "This resource, the one I just created or have otherwise gained access to? Link its management to the lifecycle of the currently running function or frame, so it gets cleaned up wh

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-25 Thread Stephen J. Turnbull
Mikhail V writes: > Good. But of course if I do it with big tables, I would anyway > need to parse them from some table file. That is the kind of thing we can dismiss (for now) as a "SMOP" = "simple matter of programming". You know how to do it, we know how to do it, if it needs optimization,

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Brendan Barnwell
On 2016-10-25 00:18, Danilo J. S. Bellini wrote: Well, see the itertools.accumulate examples yourself then, the ones at docs.python.org... We can start with something really simple like interest rates or uniform series, but... before arguing here, please convince other people to update the Wikip

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread Rob Cliffe
On 24/10/2016 06:11, Danilo J. S. Bellini wrote: For example, a product: >>> [prev * k for k in [5, 2, 4, 3] from prev = 1] [1, 5, 10, 40, 120] That makes sense for me, and seem simpler than: >>> from itertools import accumulate, chain >>> list(accumulate(chain([1], [5, 2, 4, 3]), lambda pr

[Python-ideas] f-string, for dictionaries

2016-10-25 Thread Michel Desmoulin
We have a syntax to create strings with variables automatically inferred from its context: >>> name = "Guido" >>> print(f'Hello {name}') Hello Guido Similarly, I'd like to suggest a similar feature for building dictionaries: >>> foo = 1 >>> bar = 2 >>> {:bar, :foo} {'bar': 1, 'foo', 2} And a

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Nathaniel Smith
On Tue, Oct 25, 2016 at 6:58 AM, Chris Angelico wrote: > On Wed, Oct 26, 2016 at 12:20 AM, Michel Desmoulin > wrote: >> list, set and tuple less not as good: >> >> >>> tuple(foo) >> >> TypeError: 'int' object is not iterable >> >> No raiser, no value given. It's hard to find out what's th

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Nathaniel Smith
On Tue, Oct 25, 2016 at 6:20 AM, Michel Desmoulin wrote: > Some things deserve a big explanation to solve the problem. It would be nice > to add a link to official tutorial in the documentation. > > E.G, encoding is a big one: > >In [8]: b'é' + 'é' > File "", line 1 >b'é' + 'é' >

Re: [Python-ideas] f-string, for dictionaries

2016-10-25 Thread Paul Moore
On 25 October 2016 at 20:11, Michel Desmoulin wrote: > Similarly, I'd like to suggest a similar feature for building dictionaries: > foo = 1 bar = 2 {:bar, :foo} > {'bar': 1, 'foo', 2} I don't see a huge advantage over >>> dict(foo=foo, bar=bar) Avoiding having to repeat the vari

[Python-ideas] A better interactive prompt

2016-10-25 Thread Paul Moore
I've seen a lot of syntax proposals recently that are based around providing better ways of writing "one liner" styles of code. Typically, the proposals seem to get into trouble because: 1. They duplicate things that can already be done, just not in a single expression/statement. 2. They are seen

Re: [Python-ideas] f-string, for dictionaries

2016-10-25 Thread Michel Desmoulin
Le 25/10/2016 à 22:27, Paul Moore a écrit : On 25 October 2016 at 20:11, Michel Desmoulin wrote: Similarly, I'd like to suggest a similar feature for building dictionaries: foo = 1 bar = 2 {:bar, :foo} {'bar': 1, 'foo', 2} I don't see a huge advantage over dict(foo=foo, bar=bar) Avoi

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Paul Moore
On 25 October 2016 at 20:17, Nathaniel Smith wrote: > I get that this list's default is to push > back on proposed changes, and it's a good principle in general, but > "improved error messages" are *really* cheap. The bar should be pretty > low, IMO. If someone's willing to do the work to make the

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Chris Barker
On Tue, Oct 25, 2016 at 6:58 AM, Chris Angelico wrote: > > >>> tuple(foo) > > > > TypeError: 'int' object is not iterable > > > > No raiser, no value given. It's hard to find out what's the problem is. > The > > biggest issue here is that if you have a long line with tuple() in the > > mi

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Ryan Gonzalez
So, based on everyone's feedback, I just created this: http://bugs.python.org/issue28536 On Mon, Oct 24, 2016 at 5:07 PM, Ryan Gonzalez wrote: > I personally find it kind of annoying when you have code like this: > > > x = A(1, B(2, 3)) > > > and Python's error message looks like this: > > > Ty

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-25 Thread Chris Barker
On Mon, Oct 24, 2016 at 7:00 PM, Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Chris Barker writes: > > > I think the "better error message" option is the way to go, > > however. At least until we all have better Unicode support in all > > our tools > > I don't think "

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Ryan Gonzalez
Also, as an extension of this idea, would it be possible to improve errors like this: class X: pass X() # object() takes no parameters to show the actual type instead of just 'object'? On Tue, Oct 25, 2016 at 4:48 PM, Ryan Gonzalez wrote: > So, based on everyone's feedback, I just created th

Re: [Python-ideas] A better interactive prompt

2016-10-25 Thread Chris Barker
But that's something of a solved problem. IPython offers a rich > interactive environment, for people who find the limitations of the > standard interactive prompt frustrating. Would it be worth the > standard Python documentation promoting IPython for that role? +1 iPython really makes it easier

Re: [Python-ideas] A better interactive prompt

2016-10-25 Thread Mike Miller
Would recommend bpython, it is lighter-weight and accessible to newbies, in the sense that a manual is not needed. It just starts helping out as you type. http://bpython-interpreter.org/ ___ Python-ideas mailing list Python-ideas@python.org https://m

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-25 Thread Chris Angelico
On Wed, Oct 26, 2016 at 8:50 AM, Chris Barker wrote: > that was kind of a throwaway comment, but I think it's a LONG way out, but > ideally, the OWTDI would be "curly quotes". The fact that in ASCII, a single > quote and a apostrophe are teh same, and that there is no distinction > between opening

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Nathaniel Smith
On Sat, Oct 22, 2016 at 9:02 AM, Nick Coghlan wrote: > On 20 October 2016 at 07:02, Nathaniel Smith wrote: >> The first change is to replace the outer for loop with a while/pop >> loop, so that if an exception occurs we'll know which iterables remain >> to be processed: >> >> def chain(*iterables

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-25 Thread Mikhail V
On 25 October 2016 at 19:10, Stephen J. Turnbull wrote: > So my previous thought on it was, that there could be set of such functions: > > str.translate_keep(table) - this is current translate, namely keeps > non-defined chars untouched > str.translate_drop(table) - all the same, but droppin

Re: [Python-ideas] Deterministic iterator cleanup

2016-10-25 Thread Nathaniel Smith
...Doh. I spent all that time evaluating the function-scoped-cleanup proposal from the high-level design perspective, and then immediately after hitting send, I suddenly realized that I'd missed a much more straightforward technical problem. One thing that 'with' blocks / for-scoped-iterclose do i

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-25 Thread Mikhail V
On 25 October 2016 at 23:50, Chris Barker wrote: >that was kind of a throwaway comment, >but I think it's a LONG way out, but ideally, >the OWTDI would be "curly quotes". The fact that in ASCII, >a single quote and a apostrophe are teh same, >and that there is no distinction between opening >and

Re: [Python-ideas] A better interactive prompt

2016-10-25 Thread Nathaniel Smith
On Tue, Oct 25, 2016 at 2:55 PM, Chris Barker wrote: > > >> But that's something of a solved problem. IPython offers a rich >> interactive environment, for people who find the limitations of the >> standard interactive prompt frustrating. Would it be worth the >> standard Python documentation prom

Re: [Python-ideas] Fwd: unpacking generalisations for list comprehension

2016-10-25 Thread Rob Cliffe
On 14/10/2016 07:00, Greg Ewing wrote: Neil Girdhar wrote: At the end of this discussion it might be good to get a tally of how many people think the proposal is reasonable and logical. I think it's reasonable and logical. I concur. Two points I personally find in favour, YMMV: (1) [*subs

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2016 at 04:55:21PM -0500, Ryan Gonzalez wrote: > Also, as an extension of this idea, would it be possible to improve errors > like this: > > > class X: pass > X() # object() takes no parameters > > > to show the actual type instead of just 'object'? My wild guess is that the ca

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2016 at 12:17:56PM -0700, Nathaniel Smith wrote: > I get that this list's default is to push > back on proposed changes, and it's a good principle in general, but > "improved error messages" are *really* cheap. The bar should be pretty > low, IMO. I think its even lower than most

Re: [Python-ideas] Showing qualified names when a function call fails

2016-10-25 Thread Ryan Gonzalez
Yeah, I just checked the source and tried changing it. Seems to work well. On Tue, Oct 25, 2016 at 8:11 PM, Steven D'Aprano wrote: > On Tue, Oct 25, 2016 at 04:55:21PM -0500, Ryan Gonzalez wrote: > > Also, as an extension of this idea, would it be possible to improve > errors > > like this: > >

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-25 Thread Mikhail V
On 26 October 2016 at 00:53, Mikhail V wrote: > On 25 October 2016 at 23:50, Chris Barker wrote: > >>that was kind of a throwaway comment, >>but I think it's a LONG way out, but ideally, >>the OWTDI would be "curly quotes". The fact that in ASCII, >>a single quote and a apostrophe are teh same, >

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-25 Thread Steven D'Aprano
On Tue, Oct 25, 2016 at 05:15:58PM +0200, Mikhail V wrote: [...] > >Or it can take a mapping (usually a dict) that maps either characters or > >ordinal numbers to a new string (not just a single character, but an > >arbitrary string) or ordinal numbers. > > > >str.maketrans({'a': 'A', 98: 66,

Re: [Python-ideas] Reduce/fold and scan with generator expressions and comprehensions

2016-10-25 Thread David Mertz
On Tue, Oct 25, 2016 at 1:55 PM, Rob Cliffe wrote: > > >>> [prev * k for k in [5, 2, 4, 3] from prev = 1] > [1, 5, 10, 40, 120] > > That makes sense for me, and seem simpler than: > > >>> from itertools import accumulate, chain > >>> list(accumulate(chain([1], [5, 2, 4, 3]), lambda prev, k: prev *

Re: [Python-ideas] Smart/Curly Quote Marks and cPython

2016-10-25 Thread David Mertz
This is a nice summary of quotation marks used in various languages: https://en.wikipedia.org/wiki/Quotation_mark#Specific_language_features On Tue, Oct 25, 2016 at 9:37 PM, Mikhail V wrote: > On 26 October 2016 at 00:53, Mikhail V wrote: > > On 25 October 2016 at 23:50, Chris Barker wrote: >

Re: [Python-ideas] More user-friendly version for string.translate()

2016-10-25 Thread Mikhail V
On 26 October 2016 at 03:40, Steven D'Aprano wrote: > in a "table.txt" file, and typing: > > { > 123: 456, > 124: 457, > 125: 458, > # two hundred more lines > } > > > in a "table.py" file? The difference is insignificant. And the Python > version can be cleaned up: > Ok, you have opened my eyes