def count_leading_newlines(s):
    'count number of leading newlines\n\n    this includes newlines that are separated by other whitespace\n    '
    return s[:(- len(s.lstrip()))].count('\n')
count number of leading newlines

this includes newlines that are separated by other whitespace
def count_leading_newlines(s):
    'count number of leading newlines\n\n    this includes newlines that are separated by other whitespace\n    '
    return s[:(- len(s.lstrip()))].count('\n')