[ python-Bugs-1429481 ] For loop exit early

SourceForge.net noreply at sourceforge.net
Sat Feb 11 01:13:22 CET 2006


Bugs item #1429481, was opened at 2006-02-10 19:13
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1429481&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: msmith (mike_smith)
Assigned to: Nobody/Anonymous (nobody)
Summary: For loop exit early

Initial Comment:
When I run the following snippet the "for" loop exits
early, not examining every item in the "lines" list. 
It will only print part of the list, i.e., only
approximately 65% of any list I use is printed.  (E.g.,
a list of 100 items only about 65 is printed)

If I wrap the for statement in another for statement
with a range() operator it works.

I'm pretty new to scripting, so I'm sure there's a
better way to do what I'm trying; but this seems like a
 bug.

Thanks for your help,

=========================

count = 0
lines =
["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16"]
def getnextline():
		l = lines.pop()
		l = l.strip()
		return l
for x in lines:
	count += 1
	newline = "%s,%s,\n" % (getnextline(),getnextline())
	print count, ":", newline	

Output:
---------
1 : 16,15,

2 : 14,13,

3 : 12,11,

4 : 10,9,

5 : 8,7,

6 : 6,5,

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1429481&group_id=5470


More information about the Python-bugs-list mailing list