for loop iter next if file bad

Chris Angelico rosuav at gmail.com
Wed Dec 21 04:59:58 EST 2016


On Wed, Dec 21, 2016 at 8:47 PM, Sayth Renshaw <flebber.crue at gmail.com> wrote:
> def return_files(file_list):
>     """
>     Take a list of files and return file when called.
>
>     Calling function to supply attributes
>     """
>     for file in file_list:
>         with open(os.path.join(dir_path, file), 'rb') as fd:
>             if os.stat(fd.name).st_size == 0:
>                 next(file)
>             else:
>                 yield fd

"next" doesn't do what you think it does - it tries to step the thing
you give it, as an iterator. I think you might want "continue"?

ChrisA



More information about the Python-list mailing list