Have you ever found yourself prototyping in an IPython session and wished you could easily dump all your code, in a deduplicated form, into a proper Python file? This Gist is your solution. It's designed to extract and organize your IPython history, making it simpler to transition from experimental coding to structured programming.
Paste the entire content of this Gist into a cell.
The output will display all unique import statements followed by the source code of your defined functions. This output can then be copied into a Python script file.
The Gist comprises two primary functions:
_print_import_statements()
: Extracts and prints all unique import statements from your IPython session history._print_function_sources()
: Retrieves and prints the source code of all user-defined functions (excluding those starting with an underscore).
Together, these functions enable you to capture the essence of your IPython session's codebase, neatly organized and ready for further development.