我试着把一个字典传递给一个函数,这个函数将“解析”它,但我不能迭代它,它看起来很简单,但无法理解发生了什么。在
我的职能:def _build_options(self, options):
print options
for option, value in options.iteritems():
if option not in self._optionslist:
del options[option]
return options
选项:
^{pr2}$
我的代码引发了这个问题:AttributeError: Values instance has no attribute 'iteritems'
谢谢
编辑:
类型(选项):
方向(选项):['__cmp__', '__doc__', '__init__', '__module__', '__repr__', '__str__',
'_update', '_update_careful', '_update_loose', 'changed', 'dir_marker',
'ensure_value', 'fail_fast', 'headers', 'leave_segments', 'log_level', 'meta', 'read_file', 'read_module',
'segment_container', 'segment_size', 'skip_identical', 'ttl', 'use_slo']
我尝试了options=dict(options),但得到了错误:TypeError: iteration over non-sequence
编辑2:
我有一个upload()方法,在这个方法中我调用了\u build\u options():def upload(self, paths, ttl, options):
# [...]
# print options, type(options)
# the dictionnary is well printed but its type is "instance"
opts = self._build_options(options)
upload()在其他文件中调用,如下所示:self.swift_mng.upload(filename, None, options)
我可以选择optparse.parse_参数()