W
William McBrine
Look at this -- from Python 2.5.1:
.... a.remove(x)
.... print x
....
1
2
3
5
Sure, the resulting list is correct. But 4 is never printed during the
loop!
What I was really trying to do was this:
apps = [name for name in os.listdir(ROOT) if
os.path.isdir(os.path.join(ROOT, name))]
apptitles = {}
for name in apps:
try:
app = __import__(name)
except:
apps.remove(name)
else:
apptitles[name] = getattr(app, 'TITLE', name.title())
which worked fine, until I actually had a directory with no module in it.
Then that directory was correctly removed from the list, but the _next_
one was skipped, so its title was never assigned, which caused problems
later in the program.
.... if x == 3:a = [1, 2, 3, 4, 5]
for x in a:
.... a.remove(x)
.... print x
....
1
2
3
5
a [1, 2, 4, 5]
Sure, the resulting list is correct. But 4 is never printed during the
loop!
What I was really trying to do was this:
apps = [name for name in os.listdir(ROOT) if
os.path.isdir(os.path.join(ROOT, name))]
apptitles = {}
for name in apps:
try:
app = __import__(name)
except:
apps.remove(name)
else:
apptitles[name] = getattr(app, 'TITLE', name.title())
which worked fine, until I actually had a directory with no module in it.
Then that directory was correctly removed from the list, but the _next_
one was skipped, so its title was never assigned, which caused problems
later in the program.