March 2020
Intermediate to advanced
366 pages
9h 8m
English
The first step of the script is going to be setting up the script arguments using Python's built-in argparse module:
import argparseif __name__ == '__main__': parser = argparse.ArgumentParser() img_group = parser.add_mutually_exclusive_group(required=True) img_group.add_argument('--image-dir', type=Path) img_group.add_argument('--images', type=Path, nargs='+') args = parser.parse_args()
if args.image_dir: args.images = sorted(args.image_dir.iterdir())
As you can see, we have set up two mutually exclusive arguments—--image-dir, a directory that contains the images, and --images, a list of images that we are going to use. And we make sure that we populate args.images with the list of all the images, so the ...
Read now
Unlock full access