Count number of lines in a txt file with Python excluding blank lines

python

Solution

non_blank_count = 0

with open('data.txt') as infp:
    for line in infp:
       if line.strip():
          non_blank_count += 1

print 'number of non-blank lines found %d' % non_blank_count

UPDATE: Re-read the question, OP wants to count non-blank lines .. (sigh .. thanks @RanRag). (I need a break from the computer ...)

Problem

I wish to count the number of lines in a .txt file which looks something like this: ``` apple orange pear hippo donkey ``` Where there are blank lines used to separate blocks. The result I'm looking for, based on the above sample, is five (lines). How can I achieve this? As a bonus, it would be nice to know how many blocks/paragraphs there are. So, based on the above example, that would be two blocks.

Original source