Description
Fast prototyping an idea in scripting usually means little proper modularization. Lengthy code runs from line 1 to line 500 in the same namespace. Global variables.
However, quite often, we want to turn a segment of code in a Jupyter Notebook or Codepod deck/pod into a function. There is no existing efficient, or (semi)-automatic ways to do it. We have to manually define the function by make lots of changes to the code segment. Code has to be moved to different locations of the Notebook/Codepod, or a different library/module file.
It's even worse if we want to reorganize the Notebook/Codepod into a single runable file for rerunning in a non-REPL environment. We have to manually and hierarchically reorganize code into function definitions, and move configurable variables and the top-lelvel function call(s) under if __name__ == "__main__"
The two cases above involve lots of cut-and-paste with no new algorithms implemented. This is a bad use of a programmer's time.
Can we automate or semi-automate this process?