inplace text filter - without writing file

breamoreboy at gmail.com breamoreboy at gmail.com
Sun Oct 2 01:43:08 EDT 2016


On Sunday, October 2, 2016 at 6:19:14 AM UTC+1, Sayth Renshaw wrote:
> 
> I just can't quite get it.
> 
> def return_files(file_list):
>     for filename in sorted(file_list):
>         file = os.path.join(dir_path, filename)
>         print(file)
>         with open(file) as fd:
>             print(fd)
>             for fileItem in fd:
>                 print(fileItem)
>                 for line in fileItem:
>                     print(line[0])
>                     if line.startswith('<!--'):
>                         print(line[1:])
>                         yield line[1:]
>                     else:
>                         yield line[:]
> 
> I maybe over baking it but just not getting it right.
> 
> Sayth

You've gone one level too deep, you just need:-

for line in fd:

Then split the line any way you want and yield.

Kindest regards.

Mark Lawrence.



More information about the Python-list mailing list