如何在 python 中创建或写入数据时绕过权限错误
def os_commands(): # permission error
string = '# ::2 localhostttttttttt'
with open(r'C:\Windows\System32\drivers\etc\hosts', 'r+') as h:
hosts = h.write(string)
运行此代码时出现此错误:
[Errno 13] Permission denied: 'C:\\Windows\\System32\\drivers\\etc\\hosts'
我该如何绕过 Windows 10 中的此错误