I have a Python application I'm working on, it needs to access the hosts file in order to add a few lines. Everything worked on my test file, but when I told the program to actually change my hosts file in / etc / hosts, I get IOError 13. From what I understand, my application does not have root privileges.
My question is, how can I get around this problem? Is there a way to ask the user for a password? Will the process be different if I run the application on a Windows computer?
Here is the code in question:
f = open("/etc/hosts", "a") f.write("Hello Hosts File!")
In addition, I plan to use py2app and py2exe for the final product. Will they handle the root issue for me?
source share