[2.5.1] Building loop with some exceptions?

Gilles Ganault nospam at nospam.com
Tue Nov 4 20:20:20 CET 2008


Hello

I need to call a URL through a loop that starts at 01 and ends at 99,
but some of the steps must be ignored:

=====
url = "http://www.acme.com/list?code="
p = re.compile("^(\d+)\t(.+)$")

for i=01 to 99 except 04, 34, 40, 44, 48, 54, 57, 67, 76, 83, 89:
	f = urllib.urlopen(url + i)
	page = f.read()
	f.close()

	for line in page:
		m = p.search(line)
		if m:
			code = m.group(1)
			label = m.group(2)
			
			print "Code=" + code + " # Label=" + label
=====

I'm clueless at what the Python way is to do this :-/

Thank you for any help.



More information about the Python-list mailing list