utiasSTARS / pykitti

Python tools for working with KITTI data.
MIT License
1.15k stars 239 forks source link

demo_odometry.py "TypeError: list object is not an iterator" #12

Closed fangchangma closed 7 years ago

fangchangma commented 7 years ago

After modifying the basedir variable in demo_odometry.py, running the script gives me an error

Traceback (most recent call last):
  File "demo_odometry.py", line 34, in <module>
    first_gray = next(dataset.gray)
TypeError: list object is not an iterator

It seems that Line 34 https://github.com/utiasSTARS/pykitti/blob/1819288d3ba471ce85be6450599cbf13e629245f/demos/demo_odometry.py#L34 should be replaced with

first_gray = next(iter(dataset.gray))

Same with the several lines below it.

leeclemnet commented 7 years ago

Interesting, I don't have any problem running this code without the iter() wrapper.

Two questions:

  1. What version of python are you using?
  2. What does type(dataset.gray) give you?
fangchangma commented 7 years ago
  1. Python 2.7.12, on Ubuntu 16.04
  2. <type 'list'>
leeclemnet commented 7 years ago

This seems to be a Python 2 vs 3 thing. In Python 3 the generators yield a zip object, which is already iterable, so you don't need the iter wrapper to call next on it. Adding iter to the next calls in the demo code doesn't seem to break anything, and the list in Python 2 should still be iterable in a for loop, so no problems for normal usage. I'll merge https://github.com/utiasSTARS/pykitti/pull/13 and update demo_raw.py to match. Thanks.

fangchangma commented 7 years ago

Thanks!