replace line #1 with "newline\n" in text file

Jeremy Kauffman jeremy_kauffman at
Wed Dec 24 14:57:26 CET 2003

"bmgz" <bmgz at dev.null> wrote in message news:<3fe955b8.0 at>...
> Hiya,
> I am trying to replace the first line of a config file.. with a new string
> been googlizing and reading the python manual.. but can't find what I need..
> it's all rubbish about bits and bytes etc..

something like:

lines = open('config.txt', 'r').readlines()
lines[0] = 'newline\n'
open('newconfig.txt', 'w').writelines(lines)

More information about the Python-list mailing list