for loop iter next if file bad

Joaquin Alzola Joaquin.Alzola at
Wed Dec 21 04:55:45 EST 2016

>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( == 0:
>                next(file)
>            else:
>                yield fd

>Exact error is:

>C:\Users\Sayth\Anaconda3\envs\race\python.exe C:/Users/Sayth/PycharmProjects/bs4race/ data/ -e *.xml
>Traceback (most recent call last):
 > File "C:/Users/Sayth/PycharmProjects/bs4race/", line 98, in <module>
>    data_attr(rootObs)
>  File "C:/Users/Sayth/PycharmProjects/bs4race/", line 51, in data_attr
>    for xml_data in roots:
>  File "C:/Users/Sayth/PycharmProjects/bs4race/", line 32, in return_files
>    next(file)
>TypeError: 'str' object is not an iterator

The iterator is file_list not file.
File is a str. As the exception mentions.

I suppose you want there a "continue" to iterate to the next value in the file_list

This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt.

More information about the Python-list mailing list