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

Jeremy Kauffman jeremy_kauffman at hotmail.com
Wed Dec 24 08:57:26 EST 2003


"bmgz" <bmgz at dev.null> wrote in message news:<3fe955b8.0 at news1.mweb.co.za>...
> 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