Get UID of username

Hallvard B Furuseth (nospam nospam) h.b.furuseth at usit.uio.no
Mon Jan 5 12:33:35 EST 2004


Florian Lindner wrote:

> how can I find out the UID of a username on a linux system?

from pwd import getpwnam
try:
    print getpwnam('someuser')[2]
except KeyError:
    pass

See <http://www.python.org/doc/current/lib/module-pwd.html>.

-- 
Hallvard



More information about the Python-list mailing list