Open file with sudo in python

0

I need to create a file and write it in root mode. I tried with f = open("hola.log", 'w+') but when I run it I get: PermissionError: [Errno 13] Permission denied I'm working with python3. Any ideas?

    
asked by Yamila Marucci 09.02.2018 в 01:06
source

2 answers

0

The solution was as simple as running the script with sudo. Thank you all

    
answered by 09.02.2018 в 01:20
0

You can also change the file permissions with the chmod command:

chmod 777 'hola.log'

Indicating 777 you grant all the permissions to all the users, if you want to consult how to grant certain permissions only to certain users, consult the documentation. man chmod

    
answered by 09.02.2018 в 10:14