source for the property function

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Tue Sep 2 12:45:35 EDT 2008


Rowland Smith a écrit :
> Anyone know where the source code for the built-in property function

Actually, it's a class, not a function.

> is 
> located in a python distribution?

property being a builtin type, you should find it somewhere in the 
CPython's C source AFAICT.

> I would like to see how it works - mainly, how does it know which class 
> it is being called from?

No need to look at the source for this - it's just an application of the 
descriptor protocol. Look up the doc on python.org, or google for python 
descriptor protocol. FWIW, it's the same protocol that is used for 
turning functions into methods, and writing your own custom descriptors 
is trivial.

HTH



More information about the Python-list mailing list