हिंदी
तमिलनाडु बोर्ड ऑफ सेकेंडरी एज्युकेशनएचएससी विज्ञान कक्षा १२

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

Advertisements
Advertisements

प्रश्न

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

संक्षेप में उत्तर
Advertisements

उत्तर

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++
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 14: Importing C++ programs in Python - Evaluation [पृष्ठ २९०]

APPEARS IN

सामाचीर कलवी Computer Science [English] Class 12 TN Board
अध्याय 14 Importing C++ programs in Python
Evaluation | Q 4. | पृष्ठ २९०
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×