import re


def number_of_lines(fname, count_comment_lines=False):
    """Return number of lines in file.

    Parameters
    ----------
    fname: string
        Input file name
    count_comment_lines: boolean
        If False (default), do not include comment lines in count

    Returns
    -------
    num_lines: integer
        Number of lines in file (0 for empty file)
    """

    if count_comment_lines is True:
        num_lines = sum(1 for line in open(fname))
    else:
        num_lines = 0
        pattern   = '\s*#' # Comment with 0 or more preceding whitespace characters
        for line in open(fname):
            if re.match(pattern, line):   # Look for match at beginning of string
                continue
            num_lines += 1

    return num_lines