import grp


def check_gid(gid):
    """ Get numerical GID of a group.

        Raises:
            KeyError: Unknown group name.
    """
    try:
        return 0 + gid  # already numerical?
    except TypeError:
        if gid.isdigit():
            return int(gid)
        else:
            return grp.getgrnam(gid).gr_gid