What does the sys module do in python?
and what is sys.argv?
That's exactly where I checked. I don't understand what the documentation says..
More specifically I don't understand this
The list of command line arguments passed to a Python script. argv is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv is set to the string '-c'. If no script name was passed to the Python interpreter, argv is the empty string."
Maybe a little example will help ...
import sys args = sys.argv print(args) print( "Source file: %s" % args ) # use any of these arguments in your code print( "Argument one: %s" % args ) print( "Argument two: %s" % args ) """ my output after saving this code as sysargs1.py and entering a few arguments on the command line --> ['D:/Python25/Bull/sysargs1.py', 'myarg1', 'myarg2'] Source file: D:/Python25/Bull/sysargs1.py Argument one: myarg1 Argument two: myarg2 """
So for the last two to have values, is it compulsory for the program to be run via command line?
You can run it with module subprocess as well
import subprocess child = subprocess.Popen("sysargs1.py myarg1 myrag2", shell=True)
What does that module do?
It allows your program to launch other programs and communicate with them.