[Tutor] Strange behaviour in a list

Charlie Clark charlie@begeistert.org
Sat, 03 Nov 2001 15:51:48 +0100


Dear list,

I've just noted rather strange behaviour when running through a list. I've got a script that collects URLs from a web page and then systematically calls each URL 
individually. This is an extract from the script

src = urllib.urlopen(src)
articles += munig.get_articles(src)  # a direct assign would be nicer
for article in articles:
		src = urllib.urlopen(base_url + article['link'])
		print "getting ", article['headline']
		place = munig.party(src)
		place['headline'] = article['headline']
		places.append(place)
		src.close()
		articles.remove(article)  #currently necessary

I noticed that when I run this script inside another loop the inner loop seems to step through "articles" two entries at a time. This is the output generated while I check 
this.

[{'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=3', 'headline': 'Adria'},
 {'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=7', 'headline': 'Aficionado'}, 
{'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=16', 'headline': 'Alte Post'}, 
{'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=17', 'headline': 'Alter Simpel'},
 {'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=18', 'headline': 'Alter Wirt'}, 
{'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=315', 'headline': 'Alter Wirt Forstenried'}, 
{'link': 'index.phtml?Source=adressen&Kathegorie=Gastronomie&nr=321', 'headline': 'Alter Wirt Ramersdorf'}, 
....
getting  Adria
address at 27373
getting  Alte Post
address at 27373
no description
getting  Alter Wirt
address at 27373
no description
getting  Alter Wirt Ramersdorf
address at 27373
no description
....

Any ideas why this is happening and how it's best to correct?
Charlie

Charlie Clark
Helmholtzstr. 20
Düsseldorf
40215
Tel: +49-178-782-6226