Command line arguments can be really useful when setting up python scripts on your machine to run as executable files. They can be useful also when you require user input once at the beginning and never again through the rest of the script. In this article, I wanted to go through a simple example of how this is done. Consider this simple example:
import sys
print("Command line arguments have been passed: ")
i = 0
for arg in sys.argv:
if i == 0:
print("This one doesn't count " + str(sys.argv[i]))
else:
print(sys.argv[i])
i += 1
Tutor Jobs Online – Start your Career as an Online Tutor
In this example, you should see all of the command line arguments sent in with the call to the python interpreter to run this script. The script uses the sys module to grab the command line arguments using the argv array, which contains all of the command line arguments that are passed. I’ll be using PyCharm for this example, but it’s not necessary. If you are using PyCharm, create a separate python file for this script and call it commandLineArguments.py:

You can then create a separate run/debug configuration for this script and pass in a few command line arguments(parameters in configuration) to test the script:

When you run your script, you will see this output:

As a final note, notice that the first item inside of the argv array is the file path to your script, which means that your command line arguments start at index 1.
My Freelance Paycheck – Become A Work From Home Freelancer Today