I learned from a similar question on imports that one should not mix "operational code" and import
(they should be at the top).
What is the consensus around defining functions in the middle of "operational code"?
I have a case where a function is used in just one place (it has to be a function) and having its definition close to that piece of code would make sense (all would be grouped together). It visually breaks the flow of the code, though.
Any advice from PEP? (I did not find anything relevant, as opposed to import
)
EDIT: the apparent trend in the answers is that it is not a nice thing to do, but unlike the import
case mentioned above there are no definitive directives (PEP for instance)
do stuff; and more stuff; by the way, here's how you remove invalid characters for a string; remove invalid characters for all strings; do other stuff
. – Highborn