[Tutor] a quick Q: how to use for loop to read a series of files with .doc end

Alan Gauld alan.gauld at btinternet.com
Fri Oct 7 17:03:26 CEST 2011

On 07/10/11 13:21, lina wrote:

>     One simple explanation:  it continued on to the next file, which has
>     neither "E" nor "B" in it.
> In this directory, I only kept one file. try.xpm
>   $ more try.xpm
> aaEbb
> aEEbb
> EaEbb
> EaEbE
> $ ls
> counter-vertically-v2.py  try.xpm
> counter-vertically.py   try.txt

That's 4 files.
And your code will try to process all of them, including the Python scripts.

I think that's a fundamental problem, you should use glob.glob() to 
ensure you only process the files you are interested in.

Alan G
Author of the Learn to Program web site

More information about the Tutor mailing list