Re: storing references instead of copies in a dictionary

2008-07-18 Thread castironpi
On Jul 18, 1:32 am, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 18, 4:26 pm, castironpi <[EMAIL PROTECTED]> wrote: > > > I delicately ask for an example in natural language and daily life in > > which we change what object a name refers to, > > her, him, it, ... i.e. any pronoun In that case,

Re: storing references instead of copies in a dictionary

2008-07-18 Thread [EMAIL PROTECTED]
On 17 juil, 15:56, mk <[EMAIL PROTECTED]> wrote: > Calvin Spealman wrote: > > To your actual problem... Why do you wanna do this anyway? If you want > > to change the function in the dictionary, why don't you simply define > > the functions you'll want to use, and change the one you have bound to >

Re: storing references instead of copies in a dictionary

2008-07-17 Thread John Machin
On Jul 18, 4:26 pm, castironpi <[EMAIL PROTECTED]> wrote: > I delicately ask for an example in natural language and daily life in > which we change what object a name refers to, her, him, it, ... i.e. any pronoun -- http://mail.python.org/mailman/listinfo/python-list

Re: storing references instead of copies in a dictionary

2008-07-17 Thread castironpi
On Jul 17, 7:36 pm, bgeddy <[EMAIL PROTECTED]> wrote: > bgeddy wrote: > > castironpi wrote: > >> On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote: > def f2(arg): >     return "f2 "+arg > def f1(arg): >     return "f1 "+arg > a={"1":"f1","2":"f2"} > print [eval(x[1])(x

Re: storing references instead of copies in a dictionary

2008-07-17 Thread John Machin
On Jul 18, 10:36 am, bgeddy <[EMAIL PROTECTED]> wrote: [snip] > the OP's post revolved around having a rewritable > set of "labels" - which could be recorded at one time and when re > referenced the new definitions of those labels would be used. For > example a "collection" (list,dictionary,tuple)

Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy
bgeddy wrote: castironpi wrote: On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote: def f2(arg): return "f2 "+arg def f1(arg): return "f1 "+arg a={"1":"f1","2":"f2"} print [eval(x[1])(x[0]) for x in a.items()] def f2(arg): return "New f2 "+arg print [eval(x[1])(x[0]) for x in a.items

Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy
castironpi wrote: On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote: def f2(arg): return "f2 "+arg def f1(arg): return "f1 "+arg a={"1":"f1","2":"f2"} print [eval(x[1])(x[0]) for x in a.items()] def f2(arg): return "New f2 "+arg print [eval(x[1])(x[0]) for x in a.items()] Neat trick

Re: storing references instead of copies in a dictionary

2008-07-17 Thread castironpi
On Jul 17, 10:05 am, mk <[EMAIL PROTECTED]> wrote: > > def f2(arg): > >     return "f2 "+arg > > > def f1(arg): > >     return "f1 "+arg > > > a={"1":"f1","2":"f2"} > > print [eval(x[1])(x[0]) for x in a.items()] > > def f2(arg): > >     return "New f2 "+arg > > print [eval(x[1])(x[0]) for x in a.i

Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk
def f2(arg): return "f2 "+arg def f1(arg): return "f1 "+arg a={"1":"f1","2":"f2"} print [eval(x[1])(x[0]) for x in a.items()] def f2(arg): return "New f2 "+arg print [eval(x[1])(x[0]) for x in a.items()] Neat trick, if probably dangerous in some circumstances. Anyway, thanks, I

Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk
Uwe Schmitt wrote: Python stores references in dictionaries and does not copy ! (unless you explicitly use the copy module) ! In your case the entry in the dictionary is a reference to the same object which f1 references, that is the object at 0xb7f0ba04. If you now say "f1=...:" then f1 refere

Re: storing references instead of copies in a dictionary

2008-07-17 Thread bgeddy
mk wrote: Calvin Spealman wrote: To your actual problem... Why do you wanna do this anyway? If you want to change the function in the dictionary, why don't you simply define the functions you'll want to use, and change the one you have bound to the key in the dictionary when you want to change i

Re: storing references instead of copies in a dictionary

2008-07-17 Thread mk
Calvin Spealman wrote: To your actual problem... Why do you wanna do this anyway? If you want to change the function in the dictionary, why don't you simply define the functions you'll want to use, and change the one you have bound to the key in the dictionary when you want to change it? In other

Re: storing references instead of copies in a dictionary

2008-07-17 Thread Calvin Spealman
On Thu, Jul 17, 2008 at 7:45 AM, mk <[EMAIL PROTECTED]> wrote: > Hello everyone, > > I'm storing functions in a dictionary (this is basically for cooking up my > own fancy schmancy callback scheme, mainly for learning purpose): > def f2(arg): > ... return "f2 " + arg > ... def f1

Re: storing references instead of copies in a dictionary

2008-07-17 Thread John Machin
On Jul 17, 9:45 pm, mk <[EMAIL PROTECTED]> wrote: > Hello everyone, > > I'm storing functions in a dictionary (this is basically for cooking up > my own fancy schmancy callback scheme, mainly for learning purpose): > > >>> def f2(arg): > ... return "f2 " + arg > ... > >>> > >>> def f1(arg):

Re: storing references instead of copies in a dictionary

2008-07-17 Thread Uwe Schmitt
On 17 Jul., 13:45, mk <[EMAIL PROTECTED]> wrote: > Hello everyone, > > I'm storing functions in a dictionary (this is basically for cooking up > my own fancy schmancy callback scheme, mainly for learning purpose): > >  >>> def f2(arg): > ...     return "f2 " + arg > ... >  >>> >  >>> def f1(arg): >

storing references instead of copies in a dictionary

2008-07-17 Thread mk
Hello everyone, I'm storing functions in a dictionary (this is basically for cooking up my own fancy schmancy callback scheme, mainly for learning purpose): >>> def f2(arg): ... return "f2 " + arg ... >>> >>> def f1(arg): ... return "f1" + arg ... >>> a={'1': f1, '2': f2} >>> >>> [ x[