python字典类型可迭代_无法迭代python字典

我试着把一个字典传递给一个函数,这个函数将“解析”它,但我不能迭代它,它看起来很简单,但无法理解发生了什么。在

我的职能: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_参数()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值