if line is not None: probably does not work the way you expect. You might try if line.strip(): Take a look at this quick example
test_lines = ["Number 1\n", "\n", ""] for ctr, line in enumerate(test_lines): print ctr, line if line is not None: print " not None" -- http://mail.python.org/mailman/listinfo/python-list