[Tutor] a quick Q: how to use for loop to read a series of files with .doc end
Andreas Perstinger
andreas.perstinger at gmx.net
Sat Oct 8 09:37:23 CEST 2011
On 2011-10-08 09:12, lina wrote:
> $ python3 counter-vertically-WORKING.py
> [26, 22, 28, 30, 32, 27, 30, 29, 28, 30, 32, 24, 27, 27, 28, 30, 32, 30, 33,
> 27, 33, 32, 34, 31, 28, 34, 33, 32, 25, 35, 30, 32, 30, 32, 25, 30, 26, 24,
> 33, 28, 27, 26, 23, 27, 27, 28, 27, 25, 24, 23, 23, 27, 24, 27, 26, 23, 17,
> 25, 21, 28, 21, 15, 24, 21, 12, 11, 9, 15, 20, 15, 15, 22, 29, 30, 23, 21,
> 29, 31, 17, 26, 21, 23, 23, 19, 25, 21, 27, 23, 25, 30, 26, 23, 25, 23, 25,
> 30, 28, 29, 25, 26, 28, 23, 26, 30, 25, 25, 21, 23, 23, 25, 21, 25, 25, 23,
> 30, 29, 28, 27, 27, 29, 27, 23, 27, 29, 21, 24, 23, 21, 25, 23, 26, 23, 23,
> 23, 23, 24, 25, 21, 23, 23, 23, 25, 25, 30, 25, 23, 26, 24, 28, 25, 25, 23,
> 23, 19, 23, 23, 21, 25, 18, 23, 21, 25, 21, 23, 25, 23, 22, 23, 21, 28, 25,
> 24, 21, 20, 21, 14, 23, 21, 13, 14, 21, 23, 24, 29, 26, 26, 21, 17, 19, 23,
> 21, 24, 26, 24, 26, 29, 29, 28, 28, 21, 24]
> Traceback (most recent call last):
> File "counter-vertically-WORKING.py", line 26, in<module>
> results[ch][col]+=1
> IndexError: list index out of range
>
> still the same, and only one txt coming out. the others did not process.
>
> $ ls *.xpm *.txt
> ss_0.xpm ss_1.xpm ss_4.xpm ss_7.xpm ss_9.xpm
> ss_10.xpm ss_2.xpm ss_5.xpm
> ss_1.txt ss_3.xpm ss_6.xpm ss_8.xpm
Strange, if I do
$ python3.2 counter-vertically-WORKING.py
it prints all results and also creates all txt-files:
$ ls *.xpm *.txt
ss_0.txt ss_0.xpm ss_1.txt ss_1.xpm ss_2.txt ss_2.xpm
Please insert "print(fileName)" as the first line in your main for-loop
so we can see on which file the program hangs.
Bye, Andreas
More information about the Tutor
mailing list