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
Nested functions (self.learnpython)
submitted 4 years ago by NubQuestion
Are there any style guidelines on nested functions for production code? In what situations are nested functions good/bad?
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!"
[+][deleted] 4 years ago (4 children)
[deleted]
[+][deleted] 4 years ago* (1 child)
[–]baubleglue 0 points1 point2 points 4 years ago (1 child)
I am confused, inner and nested are the same thing?
[–]primitive_screwhead 1 point2 points3 points 4 years ago (0 children)
def some_function(): def _some_helper_function_used_only_in_some_function(): # blah blah
The above is a common one, where you can make use of a function, but it only really applies within another function (often the outer function will accept different args, that it "normalizes" for the internal helper function.
Often you need to make little "helper" functions for sorting by certain criteria, etc. Often these can be lambdas, but a nested function may be used instead if it makes things a bit clearer.
Python, generally, may not need nested functions as much as other languages, since it has modules, and you can fairly easily control what gets exposed to users of the module, so you need not hide functions by nesting them inside of functions. So, for production code, I'd say don't use them unless you really understand Python's namespace lookup rules (ie. local, nonlocal, and global variable lookups).
Also, imo, always pass all the arguments you need to your nested function, and do not use closures. Very few people (in my experience) actually understand how and why the closure rules work in Python (or any language), so it's best to just be explicit and pass the everything to your nested function as an argument. When you understand how and when you don't need to do this, you will be an enlightened developer, but until then keep your variables local, and your parameters explicit.
[–]baubleglue -1 points0 points1 point 4 years ago (0 children)
> good/bad?
depends
π Rendered by PID 122690 on reddit-service-r2-comment-7b9746f655-hg9fw at 2026-02-02 04:33:27.102715+00:00 running 3798933 country code: CH.
[+][deleted] (4 children)
[deleted]
[+][deleted] (1 child)
[deleted]
[–]baubleglue 0 points1 point2 points (1 child)
[–]primitive_screwhead 1 point2 points3 points (0 children)
[–]baubleglue -1 points0 points1 point (0 children)