Help understanding Inky Impression demo code

Hey everyone,

I’m having some trouble understanding the code for the Inky Impression 7-color image.py example. I hope I don’t sound too dumb, as the program is short, but without reference documentation, I’m not able to figure out what some of the code is doing. Here’s the code in question:

#!/usr/bin/env python3

import sys

from PIL import Image

from inky.auto import auto

inky = auto(ask_user=True, verbose=True)
saturation = 0.5

if len(sys.argv) == 1:
	print("""
usage: {file} image-file""".format(file=sys.argv[0]))
	sys.exit(1)
	
image = image.open(sys.argv[i])
resizedimage = image.resize(inky.resolution)

If len(sys.argv) > 2:
	saturation = float(sys.argv[2])

inky.set_image(resized.image, saturation=saturation)
inky.show()

The things I’m having trouble understanding are:

  1. What is the parameter “sys.argv” and what is its purpose?
  2. What is the purpose of the saturation variable and what is its purpose?

Is there any documentation (other than the source code itself) that explains all the functions in the inky and PIL libraries?

I’m trying to make an image slideshow program that will rotate through and display on the Impression a series of images in a directory on the Pi.

Thanks in advance,
pete

To answer the first question, when you run a Python script from the shell or command line, e.g:

python myScript.py argument1 argument2 argument3

Anything that follows the script name, myScript.py is considered an argument to be used by the script. These all get bundled up in the list sys.argv.

So by doing sys.argv[0] will give you the script name, sys.argv[1] will give you argument1 and so on.

Doing len(sys.argv) will tell you how many parameters were passed into the script.

Hope that helps.

It does. Thank you.

Any ideas about the saturation variable?

Thanks,
pete

From the library:

    def set_image(self, image, saturation=0.5):
        """Copy an image to the display.
        :param image: PIL image to copy, must be 600x448
        :param saturation: Saturation for quantization palette - higher value results in a more saturated image

Thank you kindly, sir.