'break' Causes Execution of Procedure?

Jeff Shannon jeff at ccvcorp.com
Wed Aug 11 18:02:09 EDT 2004


Scott Brady Drummonds wrote:

>After reading your suggestion, I'm wondering why I caught the exception in
>the loop as opposed to outside of the loop.  I changed the implementation as
>you suggested and my program is now working correctly.  Of course, something
>tells me that I just covered up a bug as opposed to removing it.
>  
>

Probably you're right about that.  Better to use your original code to 
figure out what's going wrong, than to proceed with changed code that 
might not fix the problem.  Once you've found the bug,  *then* you can 
switch to catching the exception outside of the loop. ;)

If your main() function has so much code, then try breaking that down 
into several smaller functions.  It's almost certain that you can break 
a large function into several logical "sections"; if you make each of 
those sections into a separate function, it'll probably be easier to 
isolate the specific problem.

As an example, you could probably isolate that for loop within a 
subfunction --

def ProcessCycleMap(cycleMap, keys, skipList):
    for cycle in keys:
        ....

You may also want to go through your code and verify that you don't have 
anyplace that mixes tabs and spaces, which can lead to invisibly 
mismatched indentation.  It may be that the compiler sees your code 
structure a bit differently than you do...  (Best procedure here is to 
simply run tabnanny.py over your code.)

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list