Confused about properties, descriptors, and attributes...

redefined.horizons at gmail.com redefined.horizons at gmail.com
Thu Apr 20 15:41:05 EDT 2006


I've been reading about Python Classes, and I'm a little confused about
how Python stores the state of an object. I was hoping for some help.

I realize that you can't create an empty place holder for a member
variable of a Python object. It has to be given a value when defined,
or set within a method.

But what is the difference between an Attribute of a Class, a
Descriptor in a Class, and a Property in a Class?

If I had a Monster Class, and I wanted to give each Monster a member
variable called ScaryFactor, how would I define it? Does a Property
simply provide methods that access an Attribute?

Thanks,

Scott Huey

P.S. - I'm speaking about the "new" Python classes, not the "old" ones.
I hope my questions make sense.




More information about the Python-list mailing list