Change file to read-only mode in Python

前端 未结 4 2017
孤独总比滥情好
孤独总比滥情好 2020-12-06 05:13

I am writing a data processing code, in which I create a new file, write processed data in to this file and close. But the file has to be closed in read-only mode, so that i

4条回答
  •  感情败类
    2020-12-06 05:30

    I guess you could use os module after writing on your file to change the file permissions like this:

    import os
    filename=open("file_name","w")
    filename.write("my text")
    filename.close()
    os.system("chmod 444 file_name")
    

提交回复
热议问题