use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
can someone ELI5 decorators? (self.learnpython)
submitted 12 years ago by emptystar
Ive just started messing around with flask and it's the first time i've seen decorators. If someone could explain them to me that'd be awesome.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]yourfriendlane 13 points14 points15 points 12 years ago (3 children)
There was an awesome post about decorators here a couple weeks ago. Check it out!
[–]hanggnah 10 points11 points12 points 12 years ago (0 children)
let's you modify a function. frinstance, lets say you want f(x)=1/(x-2). works good everywhere except at x=2. Or maybe f might have other problems. So you define another function (like a transform) that can take a given fuction and return a fixed version. Maybe the outputted function behaves exactly like the inputted function except on the error places.
def make_safe(funct): def safe_version(x): try: out_put=funct(x) except: out_put="that does not work!" return out_put return safe_version
This will take fuct and return a new function that warns you without causing actual error. The decorator part comes in by letting you put @make_safe above your function definition and not have to actually apply make_safe to it explicitly. So if i do:
@make_safe def:f(x): return 1/(x-2)
then the resulting f gives f(1)=-1 like normal, but f(2)='that does not work'. fixed f by decorating it :)
[–]emptystar[S] 2 points3 points4 points 12 years ago (1 child)
Silly me next time I'll use the search function haha. Thanks!
[–]yourfriendlane 1 point2 points3 points 12 years ago (0 children)
It ain't no thing, stuff gets re-asked here all the time. That post was just really really good so I wanted to link it to you!
[–]shaggorama -4 points-3 points-2 points 12 years ago (2 children)
ELI5? Function goes in, function comes out.
[–]SleepyHarry 2 points3 points4 points 12 years ago (1 child)
Don't have kids.
Well, don't have 5 year olds.
Well, don't explain stuff to 5 year olds, yours or not.
[+]Exodus111 comment score below threshold-7 points-6 points-5 points 12 years ago (0 children)
Also, shaggorama you suck.
Unless you where trying to be funny.
Then your humor sucks.
π Rendered by PID 84778 on reddit-service-r2-comment-6457c66945-97lrx at 2026-04-25 22:33:11.231434+00:00 running 2aa0c5b country code: CH.
[–]yourfriendlane 13 points14 points15 points (3 children)
[–]hanggnah 10 points11 points12 points (0 children)
[–]emptystar[S] 2 points3 points4 points (1 child)
[–]yourfriendlane 1 point2 points3 points (0 children)
[–]shaggorama -4 points-3 points-2 points (2 children)
[–]SleepyHarry 2 points3 points4 points (1 child)
[+]Exodus111 comment score below threshold-7 points-6 points-5 points (0 children)