import grp


def get_gid(name):
    """Returns a gid, given a group name."""
    try:
        result = grp.getgrnam(name)
    except KeyError:
        result = None
    if result is not None:
        return result[2]
    return None