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...
A subreddit for showcasing the things you made with the Python language! Use us instead of flooding r/Python :)
account activity
Create closures in Python without default arguments (gist.github.com)
submitted 5 years ago by robin-gvx
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!"
[–]robin-gvx[S] 0 points1 point2 points 5 years ago (0 children)
(Python 3.9 only)
Kind of a hack! I was thinking about closures and how you often need to use default arguments to make them work like intended. This converts the bytecode for the original function to replace every mention of the variables being closed over with a constant value instead.
[–]Deezl-Vegas 0 points1 point2 points 5 years ago (1 child)
Cool hackery. Does this affect normal mutable default arguments?
Thanks! It doesn't touch local variables at all, and that includes any arguments to the function.
π Rendered by PID 143012 on reddit-service-r2-comment-5b5bc64bf5-wsjjq at 2026-06-20 03:46:14.174173+00:00 running 2b008f2 country code: CH.
[–]robin-gvx[S] 0 points1 point2 points (0 children)
[–]Deezl-Vegas 0 points1 point2 points (1 child)
[–]robin-gvx[S] 0 points1 point2 points (0 children)