Question

Here is some snippet code. I have tested the methods listed and they work correctly, yet when I run and test this method (countLOC) it only seems to initialize the first variable that has an instance method call (i = self.countBlankLines()). Anyone know the obvious reason I'm obviously missing?

def countLOC(self):  
    i = self.countBlankLines()  
    j = self.countDocStringLines()  
    k = self.countLines()  
    p = self.countCommentLines()  
    return k-i-j-p

This returns -3 because countBlankLines() returns 3 (correctly). however, it should return 37 as countDocStringLines() = 6 and countCommentLines() = 4 while countLines() = 50. Thanks.

Was it helpful?

Solution

If local variables were not initialized (impossible given your code!) they wouldn't be 0 -- rather, you'd get a NameError exception when you try to use them. It's 100% certain that those other method calls (except the first one) are returning 0 (or numbers totaling to 0 in the expression).

Hard to guess, not being shown their code, but from your comment my crystal ball tells me you have an iterator as an instance variable: the first method to iterate on it exhausts it, the other methods therefore find it empty.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top