def head(filepath, N):
    """ Retrieve the first N lines of a file.

    >>> from mlib._doctest import repo_path
    >>> filepath = repo_path()+"/doctest_working/workfile.txt"
    >>> with open(filepath,"w") as f: f.write("\\n".join(["Line %d"%i for i in range(100)]))
    789

    >>> print(head(filepath, 1))
    Line 0
    <BLANKLINE>

    >>> print(head(filepath, 10))
    Line 0
    Line 1
    Line 2
    Line 3
    Line 4
    Line 5
    Line 6
    Line 7
    Line 8
    Line 9
    <BLANKLINE>

    >>> rm(filepath)

    """
    try:
        with open(filepath) as f:
            return ''.join([next(f) for x in range(N)])
    except StopIteration:
        with open(filepath) as f:
            return f.read()
