Python – Final Steps to Wrap Up a Python Script into a Program

designprogramming practicespython

I finished building a Python script containing eight functions which download files, extracts them, manipulate and analyze their data and then produce graphs and export them into PNG files.

The input files are located in a remote FTP site, but some intermediate files and the output PNG files as well are saved locally in the computer file system. There are 100 lines of code in total.

Currently, I first execute it so that the Python console gets the function definitions, then I call the eight functions one by one to get the results.

For instance, I call the downloading function to download the archive files, then I call the function that extracts those files and so on.
I am sure this isn't the best way to use a Python script, so I thought of asking here if anyone could provide the steps to get the most out of my script in terms of usage. I suspect a good way would be to turn the script into one or more modules, but I am not sure at all about that.

If possible, please provide details for two possible scenarios:

  1. The script is only used by me and I do have Python installed and know how to use it
  2. The script is used by other users who don't have Python installed

Best Answer

Have the 8 function calls wrapped in

if __name__ == '__main__':

Then you can call the script by running

python NAME_OF_YOUR_SCRIPT.py

If you need to pass any variables in when running it, use the argparse module