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
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 *
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
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
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 disagree; they're both binding operations (
On 12/04, LJ wrote:
> Hi All,
>
> I have a quick question regarding the modification of global variables within
> functions. To illustrate, consider the following toy example:
>
> a={"1": set()}
> b=9
>
> def gt(l):
>a["1"] = a["1"] | set([l])
>
> When calling this last function and checking t
LJ wrote:
> Hi All,
>
> I have a quick question regarding the modification of global variables
> within functions. To illustrate, consider the following toy example:
>
> a={"1": set()}
> b=9
>
> def gt(l):
>a["1"] = a["1"] | set([l])
The difference between this example and your second one:
On Fri, Dec 5, 2014 at 10:54 AM, Dave Angel wrote:
> Python doesn't have declarations, so when a function is compiled, the
> compiler has to infer what names are to be local and what are not. The rule
> it normally uses is roughly based on whether an assignment occurs somewhere
> inside the funct
On 12/04/2014 03:09 PM, LJ wrote:
Hi All,
I have a quick question regarding the modification of global variables within
functions. To illustrate, consider the following toy example:
a={"1": set()}
b=9
def gt(l):
a["1"] = a["1"] | set([l])
When calling this last function and checking the
On Thu, Dec 4, 2014 at 1:09 PM, LJ wrote:
>
> Hi All,
>
> I have a quick question regarding the modification of global variables
within functions. To illustrate, consider the following toy example:
>
> a={"1": set()}
> b=9
>
> def gt(l):
>a["1"] = a["1"] | set([l])
>
> When calling this last f
On Fri, Dec 5, 2014 at 7:09 AM, LJ wrote:
> def gt(l):
>a["1"] = a["1"] | set([l])
>
>
> def gt2(l):
>b=b+l
These two may both look like they're assigning something, but one of
them is assigning directly to the name "b", while the other assigns to
a subscripted element of "a". In the firs
Hi All,
I have a quick question regarding the modification of global variables within
functions. To illustrate, consider the following toy example:
a={"1": set()}
b=9
def gt(l):
a["1"] = a["1"] | set([l])
When calling this last function and checking the a dictionary, I get:
>>> gt(5)
>>> a
12 matches
Mail list logo