Getting User and Group Information

The pwd module

  • Provides access to the Unix password database
     pwd.getpwuid(uid)       # Returns passwd entry for uid
     pwd.getpwname(login)    # Returns passwd entry for login
     pwd.getpwall()          # Get all entries
     
     x = pwd.getpwnam('beazley')
     # x = ('beazley','x',100,1,'David M. Beazley', '/home/beazley', 
     #      '/usr/bin/csh')

The grp module

  • Provides access to Unix group database
     grp.getgrgid(gid)      # Return group entry for gid
     grp.getgrnam(gname)    # Return group entry for gname
     grp.getgrall()         # Get all entries
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 61
July 17, 2000, beazley@cs.uchicago.edu
>>>