Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Matt Ruffalo
On 15/12/20 15:26, Grant Edwards wrote: > On 2020-12-15, Mark Polesky via Python-list wrote: > >> I see. Perhaps counterintuitive, > I guess that depends on what programming language you normally think > in. Python's handling of function parameters is exactly what I > expected, because all of the

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread 2QdxY4RzWzUUiLuE
On 2020-12-16 at 12:01:01 +1300, dn via Python-list wrote: > > On Tue, Dec 15, 2020 at 9:57 AM Mark Polesky via Python-list < > > python-list@python.org> wrote: > > > >> Hi. > >> > >> # Running this script > >> > >> D = {'a':1} > >> def get_default(): > >> print('Nobody expects this') >

Re: Library for text substitutions with calculations?

2020-12-15 Thread Terry Reedy
On 12/15/2020 11:25 AM, Bob Gailer wrote: On Tue, Dec 15, 2020, 10:42 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: On 2020-12-15 at 16:04:55 +0100, Jan Erik Moström wrote: I want to do some text substitutions but a bit more advanced than what string.Template class can do. I addition to pla

Re: Python3 change logs

2020-12-15 Thread Terry Reedy
On 12/15/2020 1:42 PM, Skip Montanaro wrote: Dang... I'm having very incomplete thoughts. Apologies for the multiple replies when one would have sufficed. https://docs.python.org/3/whatsnew/3.9.html In particular, for latest release (now 3.9) you would want tkinter in https://docs.python.org/3

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Chris Angelico
On Wed, Dec 16, 2020 at 10:03 AM dn via Python-list wrote: > > On 16/12/2020 07:52, Dan Stromberg wrote: > ...> BTW, I tend to prefer collections.defaultdict over the two argument > D.get > > or setdefault. > > > Contrarily, dict.get() seems 'better', unless (a) the dict's values are > all to be i

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread dn via Python-list
On 16/12/2020 07:52, Dan Stromberg wrote: ...> BTW, I tend to prefer collections.defaultdict over the two argument D.get or setdefault. Contrarily, dict.get() seems 'better', unless (a) the dict's values are all to be initialised to the same value, eg all None, int 0, or empty list []; or (

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread dn via Python-list
> On Tue, Dec 15, 2020 at 9:57 AM Mark Polesky via Python-list < > python-list@python.org> wrote: > >> Hi. >> >> # Running this script >> >> D = {'a':1} >> def get_default(): >> print('Nobody expects this') >> return 0 >> print(D.get('a', get_default())) >> >> # ...generates this out

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Dan Stromberg
On Tue, Dec 15, 2020 at 11:05 AM Serhiy Storchaka wrote: > 15.12.20 19:07, Mark Polesky via Python-list пише: > > # Running this script > > > > D = {'a':1} > > def get_default(): > > print('Nobody expects this') > > return 0 > > print(D.get('a', get_default())) > > > > # ...generates

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Ethan Furman
On 12/15/20 9:07 AM, Mark Polesky via Python-list wrote: > D = {'a':1} > > def get_default(): > print('Nobody expects this') > return 0 > > print(D.get('a', get_default())) Python has short-circuiting logical operations, so one way to get the behavior you're looking for is: D.get

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Grant Edwards
On 2020-12-15, Mark Polesky via Python-list wrote: > I see. Perhaps counterintuitive, I guess that depends on what programming language you normally think in. Python's handling of function parameters is exactly what I expected, because all of the previous languages I used did the same thing. Pu

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Mark Polesky via Python-list
I see. Perhaps counterintuitive, but implemented consistently. Add it to the list of gotchas, I guess. By the way... four helpful responses in under an hour, very impressive. Nice community here. Thanks to all who answered. Mark On Tuesday, December 15, 2020, 11:05:10 AM PST, Serhiy Storc

Re: Python3 change logs

2020-12-15 Thread Rich Shepard
On Tue, 15 Dec 2020, Skip Montanaro wrote: Dang... I'm having very incomplete thoughts. Apologies for the multiple replies when one would have sufficed. https://docs.python.org/3/whatsnew/3.9.html Skip, No apologies needed. That page looks like a reformatted Release Notes. Thanks again, Ric

Re: Python3 change logs

2020-12-15 Thread Rich Shepard
On Tue, 15 Dec 2020, Skip Montanaro wrote: Also, check www.python.org for "What's New" pages. I believe one is generated for every release. It will be less detailed than change logs in GitHub, but more reader friendly. Skip, I don't find a "What's New" page, but under Download -> All Releases

Re: Python3 change logs

2020-12-15 Thread Rich Shepard
On Tue, 15 Dec 2020, Skip Montanaro wrote: Change logs are kept as part of the source, I believe. Try browsing the cpython GitHub repo: https://github.com/python/cpython Skip, Thanks, I will. Stay well, Rich -- https://mail.python.org/mailman/listinfo/python-list

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Serhiy Storchaka
15.12.20 19:07, Mark Polesky via Python-list пише: > # Running this script > > D = {'a':1} > def get_default(): >     print('Nobody expects this') >     return 0 > print(D.get('a', get_default())) > > # ...generates this output: > > Nobody expects this > 1 > > ### > > Since I'm brand new t

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Chris Angelico
On Wed, Dec 16, 2020 at 4:58 AM Mark Polesky via Python-list wrote: > > Hi. > > # Running this script > > D = {'a':1} > def get_default(): > print('Nobody expects this') > return 0 > print(D.get('a', get_default())) > > # ...generates this output: > > Nobody expects this > 1 > > ### >

Re: dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Dan Stromberg
On Tue, Dec 15, 2020 at 9:57 AM Mark Polesky via Python-list < python-list@python.org> wrote: > Hi. > > # Running this script > > D = {'a':1} > def get_default(): > print('Nobody expects this') > return 0 > print(D.get('a', get_default())) > > # ...generates this output: > > Nobody exp

Re: Python3 change logs

2020-12-15 Thread Skip Montanaro
Dang... I'm having very incomplete thoughts. Apologies for the multiple replies when one would have sufficed. https://docs.python.org/3/whatsnew/3.9.html Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Python3 change logs

2020-12-15 Thread Skip Montanaro
Also, check www.python.org for "What's New" pages. I believe one is generated for every release. It will be less detailed than change logs in GitHub, but more reader friendly. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: Python3 change logs

2020-12-15 Thread Skip Montanaro
Change logs are kept as part of the source, I believe. Try browsing the cpython GitHub repo: https://github.com/python/cpython Skip On Tue, Dec 15, 2020, 10:05 AM Rich Shepard wrote: > I've upgraded from Python-3.7.x to Python-3.9.x and want to learn about > differences (if any) in tkinter bet

dict.get(key, default) evaluates default even if key exists

2020-12-15 Thread Mark Polesky via Python-list
Hi. # Running this script D = {'a':1} def get_default():     print('Nobody expects this')     return 0 print(D.get('a', get_default())) # ...generates this output: Nobody expects this 1 ### Since I'm brand new to this community, I thought I'd ask here first... Is this worthy of a bug rep

Re: Library for text substitutions with calculations?

2020-12-15 Thread Bob Gailer
On Tue, Dec 15, 2020, 10:42 AM <2qdxy4rzwzuui...@potatochowder.com> wrote: > On 2020-12-15 at 16:04:55 +0100, > Jan Erik Moström wrote: > > > I want to do some text substitutions but a bit more advanced than what > > string.Template class can do. I addition to plain text substitution I > would >

Python3 change logs

2020-12-15 Thread Rich Shepard
I've upgraded from Python-3.7.x to Python-3.9.x and want to learn about differences (if any) in tkinter between the two versions. Looking on the python.org web site I did not find change logs with the sources or under the other menus I checked. Please point me to any available logs. Regards, Ri

Re: Library for text substitutions with calculations?

2020-12-15 Thread 2QdxY4RzWzUUiLuE
On 2020-12-15 at 16:04:55 +0100, Jan Erik Moström wrote: > I want to do some text substitutions but a bit more advanced than what > string.Template class can do. I addition to plain text substitution I would > like to be able to do some calculations: > > $value+1 - If value is 16 this would inse

Library for text substitutions with calculations?

2020-12-15 Thread Jan Erik Moström
I want to do some text substitutions but a bit more advanced than what string.Template class can do. I addition to plain text substitution I would like to be able to do some calculations: $value+1 - If value is 16 this would insert 17 in the text. I would also like to subtract. $value+1w - I

SQLObject 3.9.0

2020-12-15 Thread Oleg Broytman
Hello! I'm pleased to announce version 3.9.0, the first release of branch 3.9 of SQLObject. What's new in SQLObject === Contributors for this release are: + Michael S. Root, Ameya Bapat - ``JSONCol``; + Jerry Nance - reported a bug with ``DateTime`` from ``Zope``. Feature

Re: Returning from a multiple stacked call at once

2020-12-15 Thread jak
Il 15/12/2020 12:25, Chris Angelico ha scritto: On Tue, Dec 15, 2020 at 9:56 PM jak wrote: this could be a way to emulate a long_jump: def f(i): if i < 10: i += 1 yield from f(i) else: yield i i = 0 retult = 0 for n in f(i): result = n br

Re: Returning from a multiple stacked call at once

2020-12-15 Thread jak
Il 12/12/2020 07:39, ast ha scritto: Hello In case a function recursively calls itself many times, is there a way to return a data immediately without unstacking all functions ? try this way: def path_finder(graph, start, end, path=[]): if start in path: yield None if start =

Re: Returning from a multiple stacked call at once

2020-12-15 Thread Chris Angelico
On Tue, Dec 15, 2020 at 9:56 PM jak wrote: > > this could be a way to emulate a long_jump: > > def f(i): > if i < 10: > i += 1 > yield from f(i) > else: > yield i > > i = 0 > retult = 0 > for n in f(i): > result = n > break > print(result) > Note tha

Re: Returning from a multiple stacked call at once

2020-12-15 Thread jak
Il 15/12/2020 10:41, jak ha scritto: Il 12/12/2020 18:20, Dieter Maurer ha scritto: ast wrote at 2020-12-12 07:39 +0100: In case a function recursively calls itself many times, is there a way to return a data immediately without unstacking all functions ? Python does not have "long jump"s (ou

Re: Returning from a multiple stacked call at once

2020-12-15 Thread jak
Il 12/12/2020 18:20, Dieter Maurer ha scritto: ast wrote at 2020-12-12 07:39 +0100: In case a function recursively calls itself many times, is there a way to return a data immediately without unstacking all functions ? Python does not have "long jump"s (out of many functions, many loop incarna