The following code is from a python script I'm writing that is supposed to modify the daemons array in an Arch Linux rc.conf file. However when run, I get a ValueError saying that the operation:
for line in rc:
Cannot be performed on a closed file. I may be missing something, but as far as I can tell the file is not closed. Thanks.
rc = open('/etc/rc.conf', 'r')
tmp = open('/etc/rctmp', 'w')
for line in rc:
if 'DAEMONS' in line and '#' not in line and 'dbus' not in line:
line = line.split('=')[1].strip()
line = line[1:len(line)-1]
line = line.split()
tmp = line[1:]
line = [line[0]]
line = ' '.join(line + ['dbus'] + tmp)
line = 'DAEMONS = (' + line + ')'
tmp.write(line)
rc.close()
tmp.close()
#os.remove('/etc/rc.conf')
#shutil.move('/etc/rctmp', '/etc/rc.conf')
tmp.write(line)is wrong and the rest is really weird. Anyways, paste the code and traceback as-is.