Re: function scope

2009-02-03 Thread Baris Demir
Tim Roberts wrote: Mike Kent wrote: On Feb 2, 6:40 pm, Baris Demir wrote: def simpleCut(d=dict()): temp=d for i in temp.keys(): if(temp[i] == ...) : temp[i]=new_value return temp You have been bitten by the shared default paramet

Re: function scope

2009-02-02 Thread Tim Roberts
Mike Kent wrote: > >On Feb 2, 6:40 pm, Baris Demir wrote: > >> def simpleCut(d=dict()): >>        temp=d >>        for i in temp.keys(): >>            if    (temp[i] == ...) : >>               temp[i]=new_value >> return temp > >You have been bitten by the shared default parameter noobie trap

Re: function scope

2009-02-02 Thread Steven D'Aprano
On Mon, 02 Feb 2009 16:37:07 -0800, Mike Kent wrote: > On Feb 2, 6:40 pm, Baris Demir wrote: > >> def simpleCut(d=dict()): >>        temp=d >>        for i in temp.keys(): >>            if    (temp[i] == ...) : >>               temp[i]=new_value >> return temp > > You have been bitten by th

Re: function scope

2009-02-02 Thread Mike Kent
On Feb 2, 6:40 pm, Baris Demir wrote: > def simpleCut(d=dict()): >        temp=d >        for i in temp.keys(): >            if    (temp[i] == ...) : >               temp[i]=new_value > return temp You have been bitten by the shared default parameter noobie trap: http://www.python.org/doc/fa

Re: function scope

2009-02-02 Thread Stephen Hansen
> If you want a copy when you have > to do so explicitly with "temp=d.copy()". Or that! I forgot about that method. :) Curiously, in 160k lines of code, I haven't explicitly copied a dictionary once. I find that odd. --S -- http://mail.python.org/mailman/listinfo/python-list

Re: function scope

2009-02-02 Thread Stephen Hansen
On Mon, Feb 2, 2009 at 3:40 PM, Baris Demir wrote: > Hi everybody, > > I am quite new to python and using it for my thesis. Luckily I found out > some kind of behavior surprising to me and so unwanted in my code. I could > not find any explanation, so solution for the code. > It is simply like t

Re: function scope

2009-02-02 Thread MRAB
Baris Demir wrote: > Hi everybody, > > I am quite new to python and using it for my thesis. Luckily I found > out some kind of behavior surprising to me and so unwanted in my code. I > could not find any explanation, so solution for the code. > It is simply like this: > > /*li = another_module.gl