faqts : Computers : Programming : Languages : Python : Language and Syntax : "New Style" (2.2) classes

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

I'm using properties, and "get" seems to work, but if I call "set" it all starts behaving strangely. Why?

Jul 18th, 2002 08:22
Michael Chermside,


Well, one thing that you should check is whether your class is derived
from object (is a "new-style class" not an "classic class").
If it _is_ a classic class by mistake, then the behavior you will see
will be quite odd (and difficult to diagnose). Basically, creating the
property will appear to succeed, and the "get" method will work properly
(at first). But once you attempt to set the property, instead of
invoking the "set" method, it will simply set the value directly
(classic style). This will overwrite the property, after which the "get"
method won't work either.
Since this can lead to some peculiar and difficult-to-understand bugs,
try carefully to avoid it, and double check it when you see unexpected
behavior. If you check and it IS derived from object, then you'll need
to look elsewhere for the explanation.