English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Write the syntax for getopt() and explain its arguments and return values? - Computer Science

Advertisements
Advertisements

Question

Write the syntax for getopt() and explain its arguments and return values?

Answer in Brief
Advertisements

Solution

Syntax of getopt():

, =getopt.
getopt(argv,options, [long options])
where

i) argv:
This is the argument list of values to be parsed (split). In our program, the complete command will be passed as a list.

ii) options:
This is a string of option letters that the Python program recognizes as, for input or for output, with options (like or ‘o’) that followed by a colon (r), Here a colon is used to denote the mode.

iii) long_options:
This parameter is passed with a list of strings. The argument of Long options should be followed by an equal sign C=’). In our program, the C++ file name will be passed as a string and ‘I’ also will be passed along to indicate it as the input file.

  • getopt( ) method returns value consisting of two elements.
  • Each of these values is stored separately in two different lists (arrays) opts and args.
  • opts contains a list of split strings like mode, path.
  • args contains any string if at all not split because of wrong path or mode.
  • args will be an empty array if there is no error in splitting strings by getopt().

Example:

opts, args = getopt. getopt
(argv, “i:”, [‘ifile=’])

where opts contains [(‘-i’, /c:\\pyprg\\p4′)]
-i:- option nothing but mode should be followed by:
c:\\pyprg\ \p4′ value – the absolute path of the 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 [].

shaalaa.com
Python Program to Import C++
  Is there an error in this question or solution?
Chapter 14: Importing C++ programs in Python - Evaluation [Page 290]

APPEARS IN

Samacheer Kalvi Computer Science [English] Class 12 TN Board
Chapter 14 Importing C++ programs in Python
Evaluation | Q 4. | Page 290
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×