Member-only story

Creating Secret Packages in Python

John Jarvis
3 min readSep 16, 2024

--

Generated using Copilot Designer

Sometimes I just wish I had an easy way to store variables that are going to be used over and over again.

Well, sometimes I used to wish that.

Then I learned how to make my own Python packages. Not for public consumption, but for easy access. Being a Jupyter notebook user, I don’t have the same conveniences as PyCharm users when it comes to keeping all my files and data in one place. If I want to move a Jupyter Notebook around, I have to create a folder containing some of the files it will be accessing, to move around with it. This weakness makes it easy to overlook some great features that Python has.

One of these features is the ability to import a .py file as if it were a package. As long as you keep it in the same folder as the Jupyter notebook, you can import it by typing ‘import [name of .py file]’. (There is a way to modify the PATH variable in an operating system so that you can access the file from other directories, but that is a different topic.)

These types of files can be used to store variables. Things like file paths you frequently use, access keys, or even role specific computational variables that you want to protect from exposure in your code. If you are an instructor, a frequent visitor of coding groups, or just like to share code with strangers for some reason, this can be used to give…

--

--

John Jarvis
John Jarvis

Written by John Jarvis

Data Analyst with an MBA. I write about adapting to new technology and perspectives.

No responses yet