Return the group database entry for the given group name. KeyError is raised if the entry asked for cannot be found.
Group database entries are reported as a tuple-like object, whose attributes correspond to the members of the group structure:
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
3 gr_mem all the group member’s user names
使用perl:
见^{} :
数字组ID位于索引2处,或者是倒数第二个,或者属性
gr_gid
。root
的GID为0:如果您阅读grp module documentation,您将看到grp.getgrnam(groupname)将从组数据库返回一个条目,这是一个类似元组的对象。您可以按索引或按属性访问信息:
其他条目包括名称、加密密码(通常为空,如果使用卷影文件,则为伪值)和所有组成员名称。这在任何Unix系统上都可以正常工作,包括我的Mac OS X笔记本电脑:
该模块还提供了一种通过gid获取条目的方法,正如您所发现的,还提供了一种循环遍历数据库中所有条目的方法:
最后但并非最不重要的一点是,python提供了类似的功能,可以在具有类似API的pwd和spwd模块中获取有关密码和阴影文件的信息。
相关问题 更多 >
编程相关推荐