def _count_newlines_from_end(in_str):
 try:
  i = len(in_str)
  j = (i - 1)
  while (in_str[j] == '\n'):
   j -= 1
  return ((i - 1) - j)
 except IndexError:
  return i

def _count_newlines_from_end ( in_str ) : try : i = len ( in_str ) j = ( i - 1 ) while ( in_str [ j ] == '\n' ) : j -= 1 return ( ( i - 1 ) - j ) except IndexError : return i
counts the number of newlines at the end of a string .