Question

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?

Was it helpful?

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

OTHER TIPS

From the document you linked:

values is an instance of the optparse_parser.Values class

You can further confirm this by calling type() on the return values.

Note: this happens in Python 3. A quick test shows that in Python 2 you get an old-style class (type instance).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top