Proper usage of properties in 2.2

Michael Hudson mwh at python.net
Thu Nov 22 08:51:30 EST 2001


sandskyfly at hotmail.com (Sandy Norton) writes:

> Hi,
> 
> I've been playing round with properties in 2.2b2 and I'm having a bit
> of trouble understanding what I _shouldn't_ be doing when I use them.
> For example this simple code doesn't work:
> 
> Python 2.2b2 (#26, Nov 16 2001, 11:44:11) [MSC 32 bit (Intel)] on
> win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>> Example #1
> >>> class Room:

Room needs to be a new-style class!  Change that to 

>>> class Room(object):

and it will work as you expect.

(If it makes you feel better, this confused me for ten minutes and had
me with my head in the source before I thought of this...).

> Also another minor question: how does one get access to the doc string
> of the property?

r.__class__.area.__doc__, I think.

Cheers,
M.

-- 
  I'm okay with intellegent buildings, I'm okay with non-sentient
  buildings. I have serious reservations about stupid buildings.
     -- Dan Sheppard, ucam.chat (from Owen Dunn's summary of the year)



More information about the Python-list mailing list