[Python-ideas] aliasing
Nick Coghlan
ncoghlan at gmail.com
Wed Aug 31 14:04:15 CEST 2011
On Tue, Aug 30, 2011 at 11:20 PM, Peio Borthelle
<peio.borthelle at gmail.com> wrote:
> Here I alias an expression (that's also why the arg must be a string). But I
> don't know if this last example is something good because a would have to
> stay a number (or generate an exception by calling b).
> If a is destroyed, then calling b would generate an exception...I don't have
> enough experience in python programming to really know how work the garbage
> collector, so I don't know if a could be destroyed by it.
> This is the end of my suggestion (I hope it wasn't already proposed,
> else...).
The fact that identifiers are just references to objects rather than
objects in their own right is central to the way the language works
(in a very real sense, everything of significance in a Python program
is either an object or a reference to an object).
The distinction between mutable objects (e.g. lists) and immutable
objects (e.g. tuples) is an immediate outcome of that - since the
latter can't be modified directly, the only thing you can do is change
which one you're referring to, which doesn't affect any other
references to the old value. If you want mutable state, you have to
store it on a mutable object.
Regards,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas
mailing list