newb question about @property
Steve D'Aprano
steve+python at pearwood.info
Sun Oct 1 04:54:38 EDT 2017
On Sun, 1 Oct 2017 05:46 pm, Bill wrote:
> If you were going to show non-Python users, say science undergraduates
> and faculty, that Python is an interesting tool (in 45 minutes), would
> one delve into descriptors?
Hell no :-)
I think there's a hierarchy of difficulty/complexity/mind-bogglingness in
Python. From least complex to most:
- Using Python in an imperative fashion, as in simple scripts.
- Writing your own functions.
- Writing your own classes.
- Writing generators.
- Using decorators, including property.
- Writing your own decorators.
- Writing your own descriptors.
- Writing your own metaclasses (a.k.a. "the killer joke").
I wouldn't touch the last three in a beginner's class, not unless they already
had a significant amount of programming experience.
> I am thinking maybe. Here is what I am
> thinking at this moment: trivial applications (probably), list
> comprehensions (definitely), generators (maybe briefly). Whatever I
> would discuss, I think ending with descriptors could be a strong finish.
That depends on whether your aim is to confuse them or not :-)
I don't think the descriptor protocol is something you'll be able to explain in
five or ten minutes. *Using* descriptors like property, sure, that's fine.
> But I'm certainly not merely interested for the sake of my talk, I
> obtain some satisfaction in learning how things work. If you can
> suggest any references for descriptors which you think are good, I would
> be interested.
The definitive explanation of descriptors is here:
https://docs.python.org/3/howto/descriptor.html
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list