Command-line arguments
So far, we’ve added both variable and fixed (either numeric or string) values to our code. To make our scripts more generic and more usable for other folks, we can add parameters that won’t be hardcoded within the code. If you’re not familiar with the term, hardcoded is the practice of writing fixed variable values within code. In our previous examples, we added the filename that we were going to open as a fixed value – that is, to change it, we would have to change the source code. To avoid that, we could pass the script a value (a filename, in this case) that whoever runs the script can change. Passing values to a script is what we commonly refer to as command-line arguments. We can have multiple arguments, a single argument, or as we’ve done so far, no arguments. Let’s start with a simple example, then work our way up to more complex examples that will help us make our scripts more generic.
Let’s start by...