Change file to read-only mode in Python

前端 未结 4 2022
孤独总比滥情好
孤独总比滥情好 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:45

    For Windows OS maybe to try something like this:

    import os
    
    filename = open("file_name.txt", "w")
    filename.write("my text")
    filename.close()
    os.system("attrib +r file_name.txt")
    

提交回复
热议问题