os.chown is exactly what I want, but I want to specify the user and group by name, not ID (I don't know what they are). How can I do that?
import pwd
import grp
import os
uid = pwd.getpwnam("nobody").pw_uid
gid = grp.getgrnam("nogroup").gr_gid
path = '/tmp/f.txt'
os.chown(path, uid, gid)