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

R

raocheng

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top