2 回答

TA贡献1852条经验 获得超1个赞
>>> 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

TA贡献1773条经验 获得超3个赞
从您链接的文档中:
值是
optparse_parser.Values
该类的一个实例
您可以通过调用type()
返回值来进一步确认。
注意:这是在Python 3中发生的。一项快速测试表明,在Python 2中,您获得了旧式的类(type instance
)。
添加回答
举报