简体   繁体   中英

root directory IOError: [Errno 13] Permission denied:

I am working on Ubuntu and writing a code in python. I want to add a line in a file which is placed in root directory:

ins = open( "/usr/local/etc/conf.d/test.txt", "r" )
array = []
for line in ins:
    array.append( line )
array.append('add this new line')
f = open("/usr/local/etc/gnuradio/test.txt",'w')
for line in array:
   f.write(line) 

I am getting this error:

Traceback (most recent call last):
  File "overwrite.py", line 6, in <module>
    f = open("/usr/local/etc/gnuradio/test.txt",'w')
IOError: [Errno 13] Permission denied: '/usr/local/etc/gnuradio/test.txt'

I know we do not have permission to change anything in root directory without using sudo. But is there anyway I can update this file from within my python module?

You already answered your own question: You do not have the permission to do so.

No matter if you use sh, bash, python, C, erlang or a rubber-hose attack.

Either run your script with a user owning the necessary permissions or grant yourself access to the file.

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