Using your own modules in Python

In this blog post I will detail how you can abstract your custom defined methods to stand alone python scripts and later import them into another script. This strategy can help save space in your jupyter notebook and can help clean up logic to make your debugging more easy. In my experience it is always best to abstract as much as possible, it alleiviates heart aches caused by coding mistakes and can help your development timeline.

This repl will show how this is done, essentially you write a python script in this case, and define a single function in it. Then in the master script you use a import statement, as long as that .py script is in the same directory the functions defined within will be accessible. You will notice also i aliased the import and appended that alias to the function call in You will need to use this alias when calling your functions in the main script.

import my_math as mm


Full Example in this repl. Click the files button in the top left corner to view all the files.

Repl Explanation

Ian Fogelman

Ian Fogelman

My name is Ian Fogelman. I like to develop data driven solutions with SQL Server, Python, .NET and predictive analytics.