grp — The group database


This module provides access to the Unix group database. 此模块提供对Unix组数据库的访问。It is available on all Unix versions.它在所有Unix版本上都可用。

Group database entries are reported as a tuple-like object, whose attributes correspond to the members of the group structure (Attribute field below, see <grp.h>):组数据库条目报告为一个类似元组的对象,其属性对应于group结构的成员(下面的属性字段,请参阅<grph>):

Index

Attribute

Meaning

0

gr_name

the name of the group组的名称

1

gr_passwd

the (encrypted) group password; often empty(加密的)组密码;经常是空的

2

gr_gid

the numerical group ID数字组ID

3

gr_mem

all the group member’s user names组成员的所有用户名

The gid is an integer, name and password are strings, and the member list is a list of strings. gid是一个整数,名称和密码是字符串,成员列表是字符串列表。(Note that most users are not explicitly listed as members of the group they are in according to the password database. (请注意,根据密码数据库,大多数用户并没有明确列为所属组的成员。Check both databases to get complete membership information. 请检查这两个数据库以获取完整的成员信息。Also note that a gr_name that starts with a + or - is likely to be a YP/NIS reference and may not be accessible via getgrnam() or getgrgid().)另请注意,以+-开头的gr_name可能是YP/NIS引用,可能无法通过getgrnam()getgrgid()访问。)

It defines the following items:它定义了以下项目:

grp.getgrgid(gid)

Return the group database entry for the given numeric group ID. KeyError is raised if the entry asked for cannot be found.返回给定数字组ID的组数据库条目。如果找不到所要求的条目,则会引发KeyError

Deprecated since version 3.6: 自3.6版起弃用:Since Python 3.6 the support of non-integer arguments like floats or strings in getgrgid() is deprecated.自Python 3.6以来,不赞成在getgrgid()中支持浮点或字符串等非整数参数。

grp.getgrnam(name)

Return the group database entry for the given group name. 返回给定组名称的组数据库条目。KeyError is raised if the entry asked for cannot be found.如果找不到要求的条目,则会引发KeyError

grp.getgrall()

Return a list of all available group entries, in arbitrary order.按任意顺序返回所有可用组条目的列表。

See also

Module pwd

An interface to the user database, similar to this.用户数据库的接口,与此类似。

Module spwd

An interface to the shadow password database, similar to this.影子密码数据库的接口,类似于此。