Object default value

Fredrik Lundh fredrik at pythonware.com
Wed Sep 21 09:34:21 CEST 2005

"ago" <agostino.russo at gmail.com> wrote:

> Is it possible to have a default value associated python objects? I.e.
> to flag an attribute in such a way that the assignment operator for the
> object returns the default attribute instead of the object itself, but
> calls to other object attributes are properly resolved? (I don't think
> so, but I am not sure)


You can overload certain methods to make an object behave like one
of its attributes in certain contexts (e.g. comparisions, math operations,
conversions), but you cannot do it for all operations.

Especially not the "assignment operator", since there is no such thing in
Python.  (assignment is a statement, and it's an operation on the target
namespace, not the source object).

(As always, Python works better if you use it to write Python programs)


More information about the Python-list mailing list