On Jan 30, 5:42 pm, spam <[EMAIL PROTECTED]> wrote: > Is this a bug ? > > Running the following script with Python 2.3.5: > ................ > #!/usr/bin/python > > import grp > > # groups = grp.getgrall() > > agroup = grp.getgrnam('wheel') > print agroup > print type(agroup) > > print agroup.__contains__('john') > print agroup.__contains__('x') > ................ > > This is the output I get: > ................ > ('wheel', 'x', 199, ['marcel', 'john', 'ben']) > <type 'grp.struct_group'> > False > True > ................ > > I expected __contains__ to tell me if a given user is part of a group, but > it seems that it's checking the password field ??
The tuple returned by getgrnam contains four fields: the group id (gr_gid), a list of group members (gr_grmem), the group name (gr_name), and the group password (gr_passwd). If you want to see if user 'john' is in the list of group members, use: if 'john' in agroup.gr_mem: print "Found john in group wheel" If you want to see if a password was set: if agroup.gr_passwd == "": print "No group password was set for group wheel" and so on. -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list