使用TUM的associate.py脚本报错AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘

运行脚本文件报错
在这里插入图片描述
错误原因:
python2 和python3的版本差异
在Python 3中,dict.keys()返回没有remove方法的dict_keys对象。与Python 2不同,Python 2 dict.keys()返回列表对象。
In Python 3, dict.keys() returns a dict_keys object (a view of the dictionary) which does not have remove method; unlike Python 2, where dict.keys() returns a list object.

解决办法
(1)直接强制用python2运行

python2 associate.py rgb.txt depth.txt > associate.txt

(2)还是用python3运行,小改一下源码
原本的这里

	for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches

上面加两句,把dict变为list

	# 新加的两行
	first_keys = list(first_keys)
    second_keys = list(second_keys)
    for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches

再运行(这里的python默认指向python3)

python associate.py rgb.txt depth.txt > associate.txt
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玛卡巴卡_qin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值