I need to change a line in a text file based on a criteria. I am running the following script:
fh, newMapFullName = mkstemp()
newMapFile = open (newMapFullName, 'w')
oldMapFile = open(oldMapFullName)
pattern = 'PROCESSING "CHART_SIZE_RANGE='
substr= 'PROCESSING "CHART_SIZE_RANGE= {0} {1} {2} {3} {4}"'.format("sum_all", minPix, maxPix, oldMinSum, oldMaxSum)
for line in oldMapFile:
if pattern in line:
newMapFile.write(substr)
else:
newMapFile.write(line)
This script works as intended, but changes the file permissions. I can only open the file if done from the command prompt as an administrator. I am running python 2.7 on Windows. This response suggests this is possible with os.chmod, which isn't available on Windows. Is there an equivalent process that would work?