Re: OT was Re: Python 3 removes name binding from outer scope

2017-07-26 Thread Paul Rubin
Chris Angelico writes: >>> Bipartisan-US-Bill-Moves-to-Criminalize-BDS-Support-20170720-0001.html >> Heh, at first I read that as a bill to criminalise BSD support :-) > I spluttered my drink on reading that. Good job Steven! https://en.wikipedia.org/wiki/BDS_C -- https://mail.python.org/mailman

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Steve D'Aprano
On Wed, 26 Jul 2017 06:06 am, Chris Angelico wrote: > Hmm. Aside from messing around with exec, is there any way to have a > local and a global with the same name, and use the global? Use globals['name']. There's no way to do it with regular name look ups. This doesn't work: spam = 'outside'

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Chris Angelico
On Wed, Jul 26, 2017 at 4:36 AM, eryk sun wrote: > On Tue, Jul 25, 2017 at 8:43 AM, Chris Angelico wrote: >> >> I'm not actually sure what happens if you use a global declaration at >> top level. Is it ignored? Is it an error? > > It isn't ignored, but it shouldn't make a difference since normall

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Ian Kelly
On Tue, Jul 25, 2017 at 5:38 AM, Thomas Jollans wrote: > On 2017-07-25 09:28, Chris Angelico wrote: >> It actually does the equivalent of: >> >> finally: >> e = None > > I wonder why it would bother to load None... (as someone not very > familiar with Python at the bytecode level) If I may ha

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread eryk sun
On Tue, Jul 25, 2017 at 8:43 AM, Chris Angelico wrote: > > I'm not actually sure what happens if you use a global declaration at > top level. Is it ignored? Is it an error? It isn't ignored, but it shouldn't make a difference since normally at module level locals and globals are the same. It make

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Thomas Jollans
On 2017-07-25 09:28, Chris Angelico wrote: > On Tue, Jul 25, 2017 at 4:47 PM, Rustom Mody wrote: >> +1 >> You can call it bug or bug-promoted-to-feature :D >> >> I call it surprising because I dont know of any other case in python where >> a delete is user-detectable >> ie python's delete of objec

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Chris Angelico
On Tue, Jul 25, 2017 at 6:10 PM, Ben Finney wrote: > I think those are not the only two options (the “except clause has its > own scope” behaviour is an option that could have been chosen, for > example). > > At this point the behaviour and motivation are clear, having been > revealed; I disagree

Re: OT was Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Chris Angelico
On Tue, Jul 25, 2017 at 6:33 PM, Steven D'Aprano wrote: > On Mon, 24 Jul 2017 23:47:17 -0700, Rustom Mody wrote: > > > [...] >> Bipartisan-US-Bill-Moves-to-Criminalize-BDS-Support-20170720-0001.html > > > Heh, at first I read that as a bill to criminalise BSD support :-) > I spluttered my drink o

OT was Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Steven D'Aprano
On Mon, 24 Jul 2017 23:47:17 -0700, Rustom Mody wrote: [...] > Bipartisan-US-Bill-Moves-to-Criminalize-BDS-Support-20170720-0001.html Heh, at first I read that as a bill to criminalise BSD support :-) -- “You are deluded if you think software engineers who can't write operating systems or

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Ben Finney
Steven D'Aprano writes: > On Tue, 25 Jul 2017 17:02:48 +1000, Ben Finney wrote: > > > I suppose my objection is rooted in the fact this behaviour is > > implicit; my code has not issued a ‘del’ statement, and so I don't > > expect one; yet it occurs implicitly. This violates the Zen of > > Python

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Steven D'Aprano
On Tue, 25 Jul 2017 17:02:48 +1000, Ben Finney wrote: > Ben Finney writes: > >> Having to make another name for the same object, merely to avoid some >> surprising behaviour, is IMO un-Pythonic. > > I suppose my objection is rooted in the fact this behaviour is implicit; > my code has not issue

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Steven D'Aprano
On Tue, 25 Jul 2017 00:01:11 -0700, Ethan Furman wrote: > On 07/24/2017 11:47 PM, Rustom Mody wrote: > >> Interesting to see this adjacent to news that non-participation is >> about to be criminalized double of [snip] > > Rustom, All, > > This is a Python mailing list. Please keep the topics m

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Chris Angelico
On Tue, Jul 25, 2017 at 4:47 PM, Rustom Mody wrote: > +1 > You can call it bug or bug-promoted-to-feature :D > > I call it surprising because I dont know of any other case in python where > a delete is user-detectable > ie python's delete of objects always works quietly behind the scenes whereas >

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Steven D'Aprano
On Mon, 24 Jul 2017 21:48:56 -0700, Rustom Mody wrote: > On Tuesday, July 25, 2017 at 7:12:44 AM UTC+5:30, Ben Finney quoted > Thomas Jefferson's : > >> The cost of education is trivial compared to the cost of ignorance. > > > An interesting standard of “trivial”… given… You're reading the qu

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Ben Finney
Ben Finney writes: > Having to make another name for the same object, merely to avoid some > surprising behaviour, is IMO un-Pythonic. I suppose my objection is rooted in the fact this behaviour is implicit; my code has not issued a ‘del’ statement, and so I don't expect one; yet it occurs impli

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Stefan Behnel
Ben Finney schrieb am 25.07.2017 um 08:34: > Ethan Furman writes: > >> Something like: >> >> try: >> >> except ZeroDivisionError as dead_exc: >> exc = dead_exc >> >> >> print(text_template.format(exc=exc) > > That strikes me as busy-work; the

Re: Python 3 removes name binding from outer scope

2017-07-25 Thread Ethan Furman
On 07/24/2017 11:47 PM, Rustom Mody wrote: Interesting to see this adjacent to news that non-participation is about to be criminalized double of [snip] Rustom, All, This is a Python mailing list. Please keep the topics marginally on-topic. Thanks. -- ~Ethan~ -- https://mail.python.org/ma

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Rustom Mody
On Tuesday, July 25, 2017 at 12:04:45 PM UTC+5:30, Ben Finney wrote: > Ethan Furman writes: > > > Something like: > > > > try: > > > > except ZeroDivisionError as dead_exc: > > exc = dead_exc > > > > > > print(text_template.format(exc=exc) >

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Ben Finney
Ethan Furman writes: > Something like: > > try: > > except ZeroDivisionError as dead_exc: > exc = dead_exc > > > print(text_template.format(exc=exc) That strikes me as busy-work; the name in the ‘except’ clause already *has* the object, and

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Paul Rubin
Ben Finney writes: > How can I stop Python from deleting a name binding, when that name is > used for binding the exception that is caught? Use sys.exc_info() -- https://mail.python.org/mailman/listinfo/python-list

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Rustom Mody
On Tuesday, July 25, 2017 at 7:12:44 AM UTC+5:30, Ben Finney quoted Thomas Jefferson's : > The cost of education is trivial compared to the cost of ignorance. An interesting standard of “trivial”… given… UK has risen to more than £100 billion for the first time https://www.theguardian.com/mon

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Steve D'Aprano
On Tue, 25 Jul 2017 11:41 am, Ben Finney wrote: > Howdy all, > > How can I stop Python from deleting a name binding, when that name is > used for binding the exception that is caught? When did this change in > behaviour come into Python? > > > I am writing code to run on both Python 2 and Pytho

Re: Python 3 removes name binding from outer scope

2017-07-24 Thread Ethan Furman
On 07/24/2017 06:41 PM, Ben Finney wrote: How can I stop Python from deleting a name binding, when that name is used for binding the exception that is caught? When did this change in behaviour come into Python? I am writing code to run on both Python 2 and Python 3:: exc = None try:

Python 3 removes name binding from outer scope

2017-07-24 Thread Ben Finney
Howdy all, How can I stop Python from deleting a name binding, when that name is used for binding the exception that is caught? When did this change in behaviour come into Python? I am writing code to run on both Python 2 and Python 3:: exc = None try: 1/0 text_template