문제

When I'm typing something like this in PyCharm IDE 3.0.2 Community Edition (Python 2.7.x):

directory = '/home/user/dir'
samples_list = os.walk(directory).next()[1]

I get warning in IDE Unresolved attribute reference 'next' for class 'Iterable'.

So, I want to know if this is error because of IDE (http://youtrack.jetbrains.com/issue/PY-11401) or I should do something with my code.

UPD1: Unfortunately, this is a bug in Pycharm PY-12017

도움이 되었습니까?

해결책

Your IDE is incorrect, in Python 2 iterators (including generators like os.walk()) do have a .next() method.

You can also use the built-in next() function:

samples_list = next(os.walk(directory))[1]

I suspect the IDE mismatched the generator against the collections.Iterable ABC, while generators are Iterators too.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top