Python's sys module

Learn the usage of sys module in python

The sys module provides system specific parameters and functions. We will be narrowing our study down to the following:

  • sys.argv
  • sys.executable
  • sys.exit
  • sys.modules
  • sys.path
  • sys.platform
  • sys.stdin/stdout/stderr

sys.argv

The value of sys.argv is a Python list of command line arguments that were passed to the Python script. The first argument, argv[0] is the name of the Python script itself. Depending on the platform that you are running on, the first argument may contain the full path to the script or just the file name. You should study the documentation for additional details.

Let’s try out a few examples to familiarize ourselves with this little tool:

Get hands-on with 1200+ tech skills courses.