Re: The binding operator, and what gets bound to what

2014-12-05 Thread Ned Batchelder
On 12/5/14 7:34 AM, Steven D'Aprano wrote: Ned Batchelder wrote: On 12/5/14 4:53 AM, Steven D'Aprano wrote: Oh, I learned something new: strictly speaking, this is implementation- dependent and not guaranteed to work in the future! def func(): global math import math I don't thi

Re: The binding operator, and what gets bound to what

2014-12-05 Thread Chris Angelico
On Fri, Dec 5, 2014 at 11:34 PM, Steven D'Aprano wrote: >> I don't think this is implementation-dependent. > > The docs say that it is: > > https://docs.python.org/3/reference/simple_stmts.html#the-global-statement > > Names listed in a global statement MUST NOT [emphasis added] be > defin

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Chris Angelico
On Fri, Dec 5, 2014 at 11:26 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >>> def func(): >>> global math >>> import math >> >> When would you actually *want* this, though? Given that 'import' >> already caches, there's not much point caching globally, and the idea >> that a functi

Re: The binding operator, and what gets bound to what

2014-12-05 Thread Steven D'Aprano
Ned Batchelder wrote: > On 12/5/14 4:53 AM, Steven D'Aprano wrote: >> Oh, I learned something new: strictly speaking, this is implementation- >> dependent and not guaranteed to work in the future! >> >> def func(): >> global math >> import math > > I don't think this is implementation-d

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Dec 5, 2014 at 8:53 PM, Steven D'Aprano > wrote: >> Oh, I learned something new: strictly speaking, this is implementation- >> dependent and not guaranteed to work in the future! >> >> def func(): >> global math >> import math > > When would you actually *

Re: The binding operator, and what gets bound to what

2014-12-05 Thread Ned Batchelder
On 12/5/14 4:53 AM, Steven D'Aprano wrote: Oh, I learned something new: strictly speaking, this is implementation- dependent and not guaranteed to work in the future! def func(): global math import math I don't think this is implementation-dependent. The import statement is an assi

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Chris Angelico
On Fri, Dec 5, 2014 at 8:53 PM, Steven D'Aprano wrote: > Oh, I learned something new: strictly speaking, this is implementation- > dependent and not guaranteed to work in the future! > > def func(): > global math > import math When would you actually *want* this, though? Given that 'impor

Re: The binding operator, and what gets bound to what (was: About Modifying Globals)

2014-12-05 Thread Steven D'Aprano
Ben Finney wrote: > Steven D'Aprano writes: > >> LJ wrote: >> >> > def gt(l): >> >a["1"] = a["1"] | set([l]) >> >> The difference between this example and your second one: >> >> > def gt2(l): >> >b=b+l >> >> >> is that the second is a "binding operation" and the first is not. > > I disa