title: Adding a line to Windows hosts file: PermissionError: [Errno 13] Permission denied
body: <p>I would like to add a line in my Windows hosts file via Python with this code:</p>
  
  <pre><code>fh = open("C:\Windows\System32\drivers\etc\hello.txt", "w")
  fh.write("new line")
  fh.close()
  </code></pre>
  
  <p>But I get this error:</p>
  
  <p><code>PermissionError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\drivers\\etc\\hello.txt'</code></p>
  
  <p>It doesn't work even if my antivirus is disabled.</p>
  
  <p>I don't know how to write a file as an administrator on a Windows machine.</p>