newline = os.linesep
source_fp = open('source-filename', 'r')
target_fp = open('target-filename', 'w')
first_row = True
for row in source_fp:
    if first_row:
        row = 'the first row now says this.'
first_row = False
target_fp.write(row + newline)
change first line of a file in python