[Tutor] Descriptors api doubt
Wesley Chun
wesc@deirdre.org
Mon, 14 Jan 2002 20:42:31 -0800 (PST)
On Tue, 15 Jan 2002, Karthik Gurumurthy wrote:
>
> quoting from ,
> http://www.amk.ca/python/2.2/index.html#SECTION000320000000000000000
>
> For example, when you write obj.x, the steps that Python actually perform=
s
> are:
>
> descriptor =3D obj.__class__.x
> descriptor.__get__(obj)
>
> This is what i did:
>
> class test(object):
> =09def __init__(self):
> =09=09self.name =3D "python"
>
> >>> t =3D test()
> >>> desc =3D t.__class__.name
> Traceback (most recent call last):
> File "<pyshell#15>", line 1, in ?
> ob =3D t.__class__.name
> AttributeError: type object 'test' has no attribute 'name'
>
> if python does that internally, then why am in not able to access the
> descriptor
> corresponding to "name". is it named something different?
>
> The article says the descriptors live inside clas objects.
> Does that mean they are static members ? or is something totally differen=
t?
good Python 2.2 question. i could be mistaken, but from what
i have read so far, i think that descriptors are only used/
useful for *class* attributes. you were messing with an
*instance* attribute. a class attribute is either a static
data member or a method.
i haven't checked the source to see how they have been imple-
mented in the code though. hopefully someone else can chip in
there.
hope this helps a little!
-wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall PTR, =A9 2001
http://starship.python.net/crew/wesc/cpp/
wesley.j.chun :: wesc@deirdre.org
cyberweb.consulting : henderson, nv : cyberweb@rocketmail.com
http://www.roadkill.com/~wesc/cyberweb/