I have a script that needs to be run as a super user:
$ sudo ./python-script.py
Within this script, I do some other things that do not require super user privileges.
$ os.mkdir('somefolder')
What is the best/most efficient way of creating the directory as non-root user? Should I let the script make the directory as root user, and then change permissions on it?
os.mkdirdoes allow you to specify the permissions explicitly:And you also have the option of running
os.chownto set the user and groupYou can probably get the original user like this (but it might be platform specific?)