destroy your self????

Mike Meyer mwm at
Thu Oct 20 05:35:16 CEST 2005

"KraftDiner" <bobrien18 at> writes:

> Well I guess what I'm trying to achive is the invalidate the instance
> of the object.
> I have been using None to denote an invalide or uninitialized instance
> of an object.
> There is a degenerate case in my code where a polygon has less than 3
> points and
> I want to class to flag this instance of the object as invalid.
> so.. like super.self = None  :)

You're running headlong into the fact that Python's variables are just
ways to reference objects - "names" if you will - and not objects
themselves. Whe you write "foo = some_obj", all you're doing is making
tha name "foo" refer to some_obj instead of to whatever it was
referring to before. Neither some_obj nor the object previously known
as "foo" are changed in anyway.

To make a change in the object, you have to make a change in the
object proper, not just a name that refers to it. Adding a flag that
clients can test to see if the object is still valid would do
it. Changing the operations that clients do on the object so they
raise exceptions will also work, and might be considered more

Mike Meyer <mwm at>
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

More information about the Python-list mailing list