|  | source for the property function |  | |
| | | Rowland Smith |  |
| Posted: Tue Sep 02, 2008 1:42 pm Post subject: source for the property function |  |
Anyone know where the source code for the built-in property function is located in a python distribution?
I would like to see how it works - mainly, how does it know which class it is being called from?
Thanks, Rowland |
| |
| | | Bruno Desthuilliers |  |
| Posted: Tue Sep 02, 2008 2:45 pm Post subject: Re: source for the property function |  |
Rowland Smith a écrit :
| Quote: | Anyone know where the source code for the built-in property function
|
Actually, it's a class, not a function.
| Quote: | is located in a python distribution?
|
property being a builtin type, you should find it somewhere in the CPython's C source AFAICT.
| Quote: | 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 |
| |
| | | Diez B. Roggisch |  |
| Posted: Tue Sep 02, 2008 2:49 pm Post subject: Re: source for the property function |  |
Rowland Smith schrieb:
| Quote: | Anyone know where the source code for the built-in property function is located in a python distribution?
I would like to see how it works - mainly, how does it know which class it is being called from?
|
Google the "descriptor protocol" for new-style classes. That explains it.
Diez |
| |
| | | Christian Heimes |  |
| Posted: Tue Sep 02, 2008 3:36 pm Post subject: Re: source for the property function |  |
Rowland Smith wrote:
| Quote: | Anyone know where the source code for the built-in property function is located in a python distribution?
I would like to see how it works - mainly, how does it know which class it is being called from?
|
Property is not a function but a type. Properties are a common usage for the descriptor protocol.
You can find the implementation of the property type in the file LINK
Christian |
| |
|
|