Message71230
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 |
|
Date |
User |
Action |
Args |
2008-08-16 19:29:18 | jacek | set | recipients:
+ jacek |
2008-08-16 19:29:17 | jacek | set | messageid: <1218914957.69.0.531370039263.issue3568@psf.upfronthosting.co.za> |
2008-08-16 19:29:16 | jacek | link | issue3568 messages |
2008-08-16 19:29:15 | jacek | create | |
|