Python: itertools.islice not working in a loop
问题 I have code like this: #opened file f goto_line = num_lines #Total number of lines while not found: line_str = next(itertools.islice(f, goto_line - 1, goto_line)) goto_line = goto_line/2 #checks for data, sets found to True if needed line_str is correct the first pass, but every pass after that is reading a different line then it should. So for example, goto_line starts off as 1000. It reads line 1000 just fine. Then the next loop, goto_line is 500 but it doesn't read line 500. It reads some