Search code examples
pythonparsingoptparse

What kind of object does parser.parse_args()[0] return?


As I gather from the python docs (http://docs.python.org/3.3/library/optparse.html), in the expression

(options, args) = parser.parse_args()

options is an object whose attributes are set by parser, which is an instance of the optparser class OptionParser.

What is the name of the class of which options is a member?


Solution

  • >>> import optparse
    >>> parser = optparse.OptionParser()
    >>> (options, args) = parser.parse_args()
    >>> type(options)
    <class 'optparse.Values'>
    >>> help(optparse.Values)
    Help on class Values in module optparse:
    
    class Values(builtins.object)
     |  Methods defined here:
     |  
     |  __eq__(self, other)
     |  
     |  __init__(self, defaults=None)
     |  
     |  __repr__ = _repr(self)
     |  
     |  __str__(self)
     |  
     |  ensure_value(self, attr, value)
     |  
     |  read_file(self, filename, mode='careful')
     |  
     |  read_module(self, modname, mode='careful')
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  __hash__ = None