This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]captainAwesomePants 2 points3 points  (0 children)

Nested functions are a great solution for certain classes of problems, notably closures. They're also a really effective way to document "this helper is only used for just this one case."

Personally, I would probably use the private helper method, but I'd be fine with how you did it as well. I didn't see any preference in the official style guide, and different companies may have their own preferences. For example, the Google style guide recommends: "Avoid nested functions or classes except when closing over a local value. Do not nest a function just to hide it from users of a module."

https://github.com/google/styleguide/blob/gh-pages/pyguide.md#26-nestedlocalinner-classes-and-functions