storing references instead of copies in a dictionary

castironpi castironpi at gmail.com
Fri Jul 18 13:53:26 EDT 2008


On Jul 18, 1:32 am, John Machin <sjmac... at lexicon.net> wrote:
> On Jul 18, 4:26 pm, castironpi <castiro... at gmail.com> 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,

it= Dog( )
refs[ 'it' ]= it
it.walk( )
it= Cat( )
it.feed( )

you don't want refs[ 'it' ] to refer to cat.  You were talking about
the dog when you stored refs[ 'it' ].

The OP might be wanting to mutate locals( ).  If not define a
Reference object,

class Reference:
   def __init__( self, ref ): self.ref= ref

a more descriptive name than Blank (above), to explicitly state that
you're using a reference instead of "fixed-bound" namespace semantics,
or whatever the right word is.



More information about the Python-list mailing list