counts non blank lines

def count_lines_of_code(self, fname=''):
        """ counts non blank lines """
        if fname == '':
            fname = self.fullname
        loc = 0    
        try:
            with open(fname) as f:
                for l in f:
                    if l.strip() != '':
                        loc += 1
            return loc    
        except Exception as ex:
            print('cant count lines of code in "', fname, '":', str(ex))
            return 0