[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

How to get the user/group name from uid/gid in python ?

raocheng

1/20/2008 1:44:00 AM

We know that we can get process or file's uid/gid in python. For
example:
$ python
>>> import os
>>> os.getuid()
1516
>>> os.getgid()
102
>>> os.geteuid()
1516
>>> os.getegid()
102
>>> os.getgroups()
[102, 600]
>>>


$ python
>>> import os,stat
>>> uid = os.stat("./file1")[stat.ST_UID]
>>> gid = os.stat("./file1")[stat.ST_GID]
>>> print uid, gid
1516 102
>>>

How can we get the user/group name from the uid/gid ?
Generally, we can get this information from /etc/passwd. But it is too
inconvenient and when we are using integrated password management, we
can not depend on /etc/passwd.

Thanks in advance.