I want to create a file from within a python script that is executable.
import os
import stat
os.chmod('somefile', stat.S_IEXEC)
it appears os.chmod
doesn't 'add' permissions the way unix chmod
does. With the last line commented out, the file has the filemode -rw-r--r--
, with it not commented out, the file mode is ---x------
. How can I just add the u+x
flag while keeping the rest of the modes intact?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…