Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 23, 2012 at 17:31 | comment | added | Adam Parkin | Decorators are extremely handy, but they can be a PITA to write. There's so many variations -- class based vs not class based, decorators which can decorate methods vs functions (or both), adding descriptors, decorators which take arguments, etc. So while the simple example above may not be a "hidden" feature of Python, I'd say consider it a starting point for learning about a rather beefy topic in the language, and should be in the list. | |
| Feb 16, 2012 at 7:39 | comment | added | XTL | As for useful (arguable), some more common ones: @ property, @ classmethod, @ staticmethod, @ coroutine, @ _o (monocle) | |
| Jan 15, 2012 at 7:45 | comment | added | Casey Rodarmor | Decorating a decorator with the decorator decorator? We must go deeper. | |
| Feb 7, 2011 at 16:29 | comment | added | Dzinx | @Dexter: Because that decorator may be universal -- it can be attached to any function for a short moment, e.g. when you need to debug it, and then very easily removed. Besides, there are many uses of decorators other than debugging. | |
| Feb 3, 2011 at 21:49 | comment | added | Stellar Sword | why would this be useful except in the very rare situations? Why not just redefine the function and add optional parameters? | |
| Jan 23, 2011 at 20:49 | comment | added | Kamil Szot | I thought we were supposed to list hidden features of python not the awesome features of python. ;-) | |
| Jul 25, 2010 at 23:08 | comment | added | Jesse Dhillon | If the standard is whether or not a feature is documented, then this question should be closed. | |
| May 28, 2010 at 15:26 | comment | added | Justin | Hidden? this is a documented featurepython.org/dev/peps/pep-0318 | |
| Apr 15, 2010 at 16:18 | history | edited | Personman | CC BY-SA 2.5 | added 14 characters in body |
| Apr 6, 2010 at 15:33 | comment | added | Humphrey Bogart | @vetler Most of the thing here are hardly "hidden". | |
| May 23, 2009 at 21:14 | comment | added | Johnd | vetler, the questions asks for "lesser-known but useful features of the Python programming language." How do you measure 'lesser-known but useful features'? I mean how are any of these responses hidden features? | |
| Oct 3, 2008 at 6:51 | comment | added | Dzinx | Well, it's not present in most simple Python tutorials, and I stumbled upon it a long time after I started using Python. That is what I would call a hidden feature, just about the same as other top posts here. | |
| Oct 2, 2008 at 13:52 | comment | added | Vetle | How is this a hidden feature? | |
| Sep 22, 2008 at 15:53 | comment | added | sirwart | When defining decorators, I'd recommend decorating the decorator with @decorator. It creates a decorator that preserves a functions signature when doing introspection on it. More info here:phyast.pitt.edu/~micheles/python/documentation.html | |
| Sep 21, 2008 at 15:00 | history | made wiki | Post Made Community Wiki byCommunityBot | ||
| Sep 19, 2008 at 12:32 | history | answered | Dzinx | CC BY-SA 2.5 |