In my python code, I use the fileinput module for inplace replacing:
import fileinput
for line in fileinput.FileInput("permission.txt",inplace=1):
line = line.strip()
if not 'def' in line:
print line
else:
line=line.replace(line,'zzz')
print line
fileinput.close()
However, once it is done, permission.txt permissions is now changed to root only access. I can no longer edit the file. I can only delete it.
I did some googling and it mentioned that this could be caused because fileinput creates a temporary file for this read/write replace interaction.
However, I would have thought there would be a fix for this since the bug was reported in 1999. Is it something I have to do in my code to keep the permissions the same? or is it an operating system level issue.
I'm using Python 2.6.2 on Ubuntu 9.04