anything like C++ references?

Ian Bicking ianb at colorstudy.com
Sun Jul 13 22:47:30 EDT 2003


On Sun, 2003-07-13 at 20:32, Aahz wrote:
> In article <mailman.1058126720.6756.python-list at python.org>,
> Ian Bicking  <ianb at colorstudy.com> wrote:
> >
> >(Admittedly, some confusion may occur because these very different
> >operations use the same syntax:
> >
> >  x = 10
> >  x[0] = 10
> >  obj.x = 10
> >
> >The second and third are entirely different from the first.)
> 
> No, they aren't.  They are precisely the same; they just have different
> assignment targets.

Sure they are different.  The first is a primitive operation binding the
variable x.  The second gets x, and calls x.__setitem__(0, 10), and the
third is equivalent to setattr(obj, 'x', 10).

The first is primitive syntax.  I suppose you could say that it could be
reduced to operations on locals() and globals(), but I feel like that's
a detail that is best not brought up ;)  The local and global scope are
not as flexible as other objects The other two are really just syntactic
sugar.

  Ian







More information about the Python-list mailing list