View Single Post
Old Oct 16th, 2006, 6:01 PM   #8
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
The problem is that your program never reaches a return statement. The first return statement is here. I've highlighted important lines in red:
#         for items in range(1,25):
#             ss_item = url.find(r'some text',fe_item)
#             if ss_item is -1: break
#             ss_value = ss_item
#             char_to_kill = url[ss_item-1:ss_item]
#             if url[ss_item-1:ss_item] is char_to_kill: ss_item = url.find(r'some text'ss_value+9)            
#             if ss_item is -1:
#                 if no_next is 1:
#                     return item # <------ i want to exit the loop here!
The first red line breaks out of the for-loop if ss_item is -1. This means that to reach the second red line, ss_item must not be -1. Thus, the if statement is skipped over, and the return statement is never reached.

The second return statement is outside the while loop. Since this is an infinite loop, and since you never break out of it, the second return statement is never reached either.

There is also a fair amount of code that is redundant. For example:
#             char_to_kill = url[ss_item-1:ss_item]
#             if url[ss_item-1:ss_item] is char_to_kill: ss_item = url.find(r'some text'ss_value+9)
The if statement will always evaluate to true, since you set char_to_kill to a value, and then test to see if it is that same value.

Also, it's usual to use "==" instead of "is" when testing for equality. The "==" operator checks whether something is equal to something else. The "is" operator checks to see whether two variables refer to the same object.

To use an analogy, the phrase "Tom and Bob are the same person", would be an example of "is", whereas "Tom is either a clone of Bob, or the same person", would be an example of "==".

It's a little complex, but the rule of thumb is to use "==" by default. It may save you from a few unexpected results.
Arevos is offline   Reply With Quote