Friday, December 30, 2016

Make file read-only in Python

If you want to make file read-only:

import os
from stat import S_IREAD

os.chmod('path/to/file.txt', S_IREAD)


If you want to make file writeable:

import os
from stat import S_IWRITE

os.chmod('path/to/file.txt', S_IWRITE)