Python: finding uid/gid for a given username/groupname (for os.chown)
Solution 1:
Use the pwd
and grp
modules:
from pwd import getpwnam
print getpwnam('someuser')[2]
# or
print getpwnam('someuser').pw_uid
print grp.getgrnam('somegroup')[2]
Use the pwd
and grp
modules:
from pwd import getpwnam
print getpwnam('someuser')[2]
# or
print getpwnam('someuser').pw_uid
print grp.getgrnam('somegroup')[2]