Running the script file reports an error
Cause of error.
Version difference between python2 and python3
In Python 3, dict.keys() returns the dict_keys object without the remove method. Unlike Python 2, Python 2 dict.keys() returns the list object.
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.
Solution:
(1) Directly run with Python 2 forcely:
python2 associate.py rgb.txt depth.txt > associate.txt
(2) Still run it in python 3. Make a small change to the original source code
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
Add two sentences above to change dict into list
# two new lines
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
Run again (Python here points to python3 by default)
python associate.py rgb.txt depth.txt > associate.txt
Read More:
- How to Solve Python AttributeError: ‘dict’ object has no attribute ‘item’
- [Solved] Python 3.6 Error: ‘dict’ object has no attribute ‘has_key’
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘parameters‘
- [2021-10-05] Python Error: AttributeError: ‘NoneType‘ object has no attribute ‘append‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘map‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] Add-apt-repository Command Error: AttributeError: ‘Thread‘ object has no attribute ‘isAlive‘
- [Solved] AttributeError: ‘HTMLWriter‘ object has no attribute ‘_temp_names‘
- [Solved] AttributeError: ‘PngImageFile‘ object has no attribute ‘imshow‘
- AttributeError: DatetimeProperties object has no attribute
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- [Solved] Networkx Error: Attributeerror: ‘graph’ object has no attribute ‘node’
- How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘
- [Solved] pandas ExcelWrite AttributeError: ‘NoneType‘ object has no attribute ‘group‘