verify a user

Dan Sommers me at privacy.net
Wed Jan 18 21:55:47 EST 2006


On Wed, 18 Jan 2006 18:25:19 -0700,
David Bear <david.bear at asu.edu> wrote:

> If I have a unix user name, is there a way to verify that the user
> really exists and query default group memberships?

import pwd
unix_user_name = raw_input( 'enter a user name:' )
try:
    print pwd.getpwnam( unix_user_name )
except KeyError:
    print unix_user_name, 'does not exist'

There's a grp module for making similar queries against /etc/group (or
the modern equivalent thereof).

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>



More information about the Python-list mailing list