根目录IOError:[Errno 13]权限被拒绝:

时间:2013-08-01 23:47:59

标签: python

我正在研究Ubuntu并在python中编写代码。我想在一个放在根目录中的文件中添加一行:

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) 

我收到此错误:

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'

我知道我们没有权限在没有使用sudo的情况下更改根目录中的任何内容。但无论如何我可以在我的python模块中更新这个文件吗?

1 个答案:

答案 0 :(得分:2)

您已经回答了自己的问题:您无权这样做。

无论你使用sh,bash,python,C,erlang还是橡皮管攻击。

使用拥有必要权限的用户运行脚本或授予自己对文件的访问权限。