its path will be passed as string and ‘i’ i will be also passed to indicate it as the input file. getopt() method returns value consisting of two elements . Each of these values are stored separately in two different list (arrays) opts and args .Opts contains list of splitted strings like mode and path. args contains error string, if at all the comment is given with wrong path or mode.
args will be an empty list if there is no error. For example The Python code which is going to execute the C++ file p4 in command line will have the getopt() method like the following one. opts, args = getopt.getopt (argv, "i:",['ifile=']) where opts contains [('-i', 'c:\\pyprg\\p4')] -i :- option - mode should be followed by : (colon) 'c:\\pyprg\\p4' value - absolute path of C++ file. In our examples since the entire command line commands are parsed and no leftover argument, the second argument args will be empty [].
If args is displayed using print() command it displays the output as []. >>>print(args) [] 12th Computer Chapter - - You can check out the full list of Python standard modules and what they are for. These files are in the Lib directory inside the location where Python is installed. Note Some more command for wrapping C++ code if ==' ': main(sys.argv[ :]) (A Special variable) in Python Since there is no main() function in Python, when the command to run a Python program is given to the interpreter, the code that is at level indentation (top must line of the program) is to be executed.
However, before doing that, interpreter will define a few special variables. is one such special variable which by default stores the name of the Python file. If the source file is executed as the main program, the interpreter sets the variable to have a value “ ”. is a built-in variable which evaluates to the name of the current module.
Thus it can be used to check whether the current script is being run on its own.