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

lina lina.lastname at gmail.com
Sat Oct 8 09:12:31 CEST 2011


On Sat, Oct 8, 2011 at 2:50 PM, Andreas Perstinger <
andreas.perstinger at gmx.net> wrote:

> On 2011-10-08 08:25, lina wrote:
>
>>  Still have a reading "multiple" files issue:
>>>
>>>>
>>>>  Traceback (most recent call last):
>>>>   File "counter-vertically-WORKING.****py", line 26, in<module>
>>>>
>>>>     results[ch][col]+=1
>>>>  IndexError: list index out of range
>>>>
>>>>  only one file ss_1.xpm was processed and wrote file, for the rest
>>>>  ss_2.xpm,
>>>>  ss_3.xpm and following keep intact,
>>>>
>>>>  any suggestions?
>>>>
>>>
>> https://docs.google.com/leaf?**id=**0B93SVRfpVVg3MjIxZGI5YWQtN2NiY**
>> y00MWFkLWE0ZTctNjExNGJiNjYzYjQ**w&hl=en_GB<https://docs.google.com/leaf?id=0B93SVRfpVVg3MjIxZGI5YWQtN2NiYy00MWFkLWE0ZTctNjExNGJiNjYzYjQw&hl=en_GB>
>>
>> https://docs.google.com/leaf?**id=**0B93SVRfpVVg3YjQ1ZWRkMjUtNmZhY**
>> S00MTA4LTg3YTktY2JjYzEyMDU5OTI**2&hl=en_GB<https://docs.google.com/leaf?id=0B93SVRfpVVg3YjQ1ZWRkMjUtNmZhYS00MTA4LTg3YTktY2JjYzEyMDU5OTI2&hl=en_GB>
>>
>> https://docs.google.com/leaf?**id=**0B93SVRfpVVg3YjQ1ZWRkMjUtNmZhY**
>> S00MTA4LTg3YTktY2JjYzEyMDU5OTI**2&hl=en_US<https://docs.google.com/leaf?id=0B93SVRfpVVg3YjQ1ZWRkMjUtNmZhYS00MTA4LTg3YTktY2JjYzEyMDU5OTI2&hl=en_US>
>>
>> you may rename ss_1.xpm to the ss_2 or 3, keep them the same is okay, just
>> different names.
>>
>
> Ok, I just ran your script with this files and don't get an error. Except
> some stylistic issues the code looks fine. The resulting txt-files still
> have the problem with the leading '[' and trailing ']' but I've already
> suggested a solution earlier today.
>
> Do you still get an error?



$ 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



thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111008/d05b5a65/attachment-0001.html>


More information about the Tutor mailing list