def remove_write_permissions(path):
    """Remove write permissions from this path, while keeping all other permissions intact.
    Params:
        path:  The path whose permissions to alter.
    """
NO_USER_WRITING = ~stat.S_IWUSR
NO_GROUP_WRITING = ~stat.S_IWGRP
NO_OTHER_WRITING = ~stat.S_IWOTH
NO_WRITING = NO_USER_WRITING & NO_GROUP_WRITING & NO_OTHER_WRITING
current_permissions = stat.S_IMODE(os.lstat(path).st_mode)
os.chmod(path, current_permissions & NO_WRITING)
Изменение прав доступа к файлам в питоне