This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jacek
Recipients jacek
Date 2008-08-16.19:29:15
SpamBayes Score 1.9846108e-05
Marked as misclassified No
Message-id <1218914957.69.0.531370039263.issue3568@psf.upfronthosting.co.za>
In-reply-to
Content
Hi

I wrote my first program in python, and I found bug in it.
I explain it in example (I do it under Windows XP):

1. At the begining create some directories:
>mkdir .\test\
>mkdir .\test\.svn
>mkdir .\test\cvs
>mkdir .\test\pdk

2. Next create file ".\bug.py" with content:
import re
import os

print 'example1:'
lpatternDirSkip = re.compile(r'(^cvs$)|(^[.].*)', re.IGNORECASE)
for lroot, ldirs, lfiles in os.walk(r'.\\test\\'):
   ldirIndex = 0
   for ldirName in ldirs:
      if lpatternDirSkip.search(ldirName):
         ldirs.remove(ldirName)
   print ldirs

print 'example2:'
lpatternDirSkip = re.compile(r'(^cvs$)|(^[.].*)', re.IGNORECASE)
for lroot, ldirs, lfiles in os.walk('.\\test\\'):
   ldirIndex = 0
   while ldirIndex < len(ldirs):
      if lpatternDirSkip.search(ldirs[ldirIndex]):
         ldirs.remove(ldirs[ldirIndex])
         ldirIndex -= 1
      ldirIndex += 1
   print ldirs

3. Next run cmd.exe (in the same directory) and type "bug.py". Result is:
example1:
['cvs', 'pdk']
[]
[]
example2:
['pdk']
[]

5. Comment:
In this example I want to remove from list of directories (ldirs) every
hiden directories (like ".svn") and directory "CVS". 
Example1 is the comfortable way, but it products wrong result (the "cvs"
directory is not remove). This is only happen when I remove some
directories from the list. I don't care that there was deleted one
element from the list. It should be special case, and enumeration on the
rest elements should be correct.
Example2 works correcty (it's work around of this problem).

Jacek Jaworski
History
Date User Action Args
2008-08-16 19:29:18jaceksetrecipients: + jacek
2008-08-16 19:29:17jaceksetmessageid: <1218914957.69.0.531370039263.issue3568@psf.upfronthosting.co.za>
2008-08-16 19:29:16jaceklinkissue3568 messages
2008-08-16 19:29:15jacekcreate