简体   繁体   中英

Python PermissionError: [Errno 13] Permission denied when trying to save txt to program files(x86)

I know there are other questions like this but none of them have helped. Here is the full code:

    save_path = r'C:\Program Files (x86)\Mod Tool\Infractions\Kicks'
    name_of_file = whoisit
    completeName = os.path.join(save_path, name_of_file + ".txt")
    file1 = open(completeName, "w")
    file1.write("Username: " + whoisit + "  //  "+ whatisit + " // Reason: " + reason)
    file1.close()
    print("Infraction stored.")
    print("")
    print("/kick" + ":" + whoisit + ":" + reason)
    print("")
    start()

To take you through, save_path is the folder I want it to save in (the txt will be saved in the Kicks folder)

I think that you need to run as admin in windows in order to write to program files. Try to run as administrator.

usually: right click -> run as administrator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM