getting username from uid

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Mon Sep 16 12:06:58 EDT 2002


On Monday 16 Sep 2002 2:05 pm, Rajarshi Guha wrote:
> Hi,
>   when I do a stat on a file I can get the UID of the owner. IS there
> anyway to get from UID to username (or directly to username for that
> matter)?

On *nix  look at the pwd standard module...

$ pydoc pwd
Python Library Documentation: module pwd

NAME
    pwd

FILE
    /usr/local/lib/python2.2/lib-dynload/pwd.so

DESCRIPTION
    This module provides access to the Unix password database.
    It is available on all Unix versions.

    Password database entries are reported as 7-tuples containing the
    following
    items from the password database (see `<pwd.h>'), in order:
    pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell.
    The uid and gid items are integers, all others are strings. An
    exception is raised if the entry asked for cannot be found.

FUNCTIONS
    getpwall(...)
        getpwall() -> list_of_entries
        Return a list of all available password database entries, in arbitrary 
order.
        See pwd.__doc__ for more on password database entries.

    getpwnam(...)
        getpwnam(name) -> entry
        Return the password database entry for the given user name.
        See pwd.__doc__ for more on password database entries.

    getpwuid(...)
        getpwuid(uid) -> entry
        Return the password database entry for the given numeric user ID.
        See pwd.__doc__ for more on password database entries.

DATA
    __file__ = '/usr/local/lib/python2.2/lib-dynload/pwd.so'
    __name__ = 'pwd'



HTH
Martin
-- 
### Python Powered Signature
I started writting this email on 
Mon Sep 16 16:05:22 2002





More information about the Python-list mailing list