开发者

Creating read only text files with python

Is it possible to create read only files in python which can not be changed later and in which users can not change its attribute from read-only to开发者_运维知识库 normal file?

Please suggest.

Thanks in advance.


This is not python specific.

If the files are made by a different user that the one viewing it the script can make it read-only. As the file is owned by the python user, the viewing user cannot just change the attributes.

So it's very much an OS question, and not a Python question.

Oh, and there is no way to prevent an administrator changing the file, or for the file to be readable but not copyable.


This is just impossible. Any user with administrative rights can remove readonly restrictions of any kind.

Another option might be "Write a python program to kill all users over the worls so that they would not be able to change file attributes or security settings" :-)


Take a look at os.chmod() function and execute it with appropriate parameters (filename, stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH) for your just created file.

On linux other users then you will not be able to change file or change attributes to writable.

Some root user or someone logged into you account will be able to change it though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜