In Windows, assuming proper PATH Environment variables, to pass parameters, you can invoke Python as (similar to C):
py argcargv.py "embedded space" bb cc
or
python argcargv.py "embedded space" bb cc
or
You can 'Double Click' on the Python file (argcargv.py or equivalent) in 'File Explorer' (no extra parameters).
The following was tested on Windows 10 using Python 3.6.5. In Windows, parameters containing
embedded spaces must be surrounded by double quote characters (e.g. "embedded space") .
import os
import sys
iparameter_count = len(sys.argv)
print("Number of parameters (including script name): ", iparameter_count)
print("Script name: ", sys.argv[0])
print("The parameters are: " , str(sys.argv))
print("")
for i, sParameter in enumerate(sys.argv, start=1):
print ("Parameter {}: {}".format(i, sParameter))
spath = sys.argv[0]
print("")
print("Folder name is '{}'".format(os.path.dirname(spath)))
print("Base file name is '{}'".format(os.path.basename(spath)))
print("")
#Pause only if the Program is Interactive - i.e. only 1 argument
if iparameter_count <= 1 :
programPause = input("Press the <ENTER> key to EXIT")
Output:
Number of parameters (including script name): 4
Script name: argcargv.py
The parameters are: ['argcargv.py', 'embedded space', 'bb', 'cc']
Parameter 1: argcargv.py
Parameter 2: embedded space
Parameter 3: bb
Parameter 4: cc
Folder name is ''
Base file name is 'argcargv.py'
Lewis