Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Understanding Python decorators (stackoverflow.com)
56 points by spoon16 on Aug 15, 2010 | hide | past | favorite | 6 comments


this is RTFM material and i wish i could downvote it


I don't think that it is quite RTFM material. I looked at the documentation on decorators in the python manual(actually there was only passing mention in the manual it was fleshed out in the pep3129) and it is fairly lacking. Sure it describes how the decorators operate in a syntactical sense it does not provide the motivation for them or the examples that this stack overflow question answers.


Understood. YMMV. However, I have a couple books on Python, plus the official docs, plus Google, plus the REPL shell, and between those I found more than ample information on how they work and what they're useful for.

I hope we don't reach a point here on HN where the home page is filled with questions like, "How do 'for' loops work in C?" because that would make my K&R C book cry, among other things. :)


I think decorators are a bit different than for loops but I get your gist :)

I think this article is fine for HN for a few reasons:

1. Not all python programmers know about decorators and they might not be sufficiently motivated to search them out.

2. Decorators do not have obvious utility after reading python's manual.

3. HN commentary is usually more interesting than the article and the submitter might have wanted to spark some debate on the utility of them.

4. This answer is a good example of a well written(mostly, there were some grammatical errors but overall good) through explanation that was succinct without being too succinct and leaving out important details.


I had a real hard time understanding decorators when I was learning python. The documentation is vague as hell about them. I finally had to bug someone on irc to explain them to me. (Not in #python, I got my ass chewed out)


In a real sense The Internet has been the manual for awhile now.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: