View on GitHub

coding-tutorials

Python packages

Return to the Advanced Python - Conda, packages, and scripting mainpage

← Back to Python packages

Running scripts

Running a Python script is very easy, simply call:

python script.py [arguments]

You can try it with one of mine.

Genereal strucuture

This is the script we just ran. In general:

Arguments

There are two main ways to input arguments into your script. Either as positional arguments (as above) or with argparse(preferred way)

  1. Positional arguments are simply inputed after the name of the script and then can be called inside the script using sys.argv[1]. The 0 index is the script name itself.
  2. Argparse takes a little more time to set up, but allows you to make flags, require arguments and types, and easily collect all of your inputs. There are plenty of examples online of how to use this.

    PEP8

    If you are really concerned about your code being “up to snuff”, you can adhere to the PEP8 guidelines. There are even programs that will check your work to see if you are adhering to them.

Continue to Practice →