I'm trying to open 2 files, one of which has content and one which is empty. For the lines that are not headers, I read each line and process it before writing the processed line to the empty file, until the end of the first file is reached.
I'm getting an 'Invalid syntax error on the 2nd line (with open...), and have no idea why.
try:
with open(file_read, 'r') as file_r, open(file_write, 'w') as file_w:
for line in file_r:
while line != '':
if count > 10:
line = line.split()
colour_int = int(line[-1]) # colour is stored as the last (4th) value in each line
red = (colour_int >> 16) & 255
green = (colour_int >> 8) & 255
blue = colour_int & 255
new_line = str.join([ line[0], line[1], line[2], red, green, blue ])
file_w.write(new_line + '\n')
count += 1
except IOError as e:
print 'Operation failed: %s' % e.strerror