[Tutor] editing a file

Andrei Kulakov ak@silmarill.org
Fri, 24 May 2002 04:30:49 -0400


On Fri, May 24, 2002 at 09:13:41AM +0100, steve king wrote:
> Hello everyone, the help I had last time from the tutors was so good I need 
> another fix :-)
> 
> Ok I have worked out how to read and write files (its not that hard after 
> all). But now I need to be able to edit these files. This is the situation:
> 
> In a config file I have the following:
> 
> [Main]
> AAA=
> BBB=
> CCC=
> DDD=
> 
> What I want to be able to do is insert another string like "EEE=" 
> between,say, "BBB=" and "CCC=" or anywhere in the file. How do I do this? I 
> know there is a function called seek() but the documentation is a little 
> sparse.
>
Well, if it can be anywhere in the file, append it at the end. If
you really want to insert it in between other lines, read all
lines and then write them out again, inserting it as you reach
the right place.

By the way, look at configparser module.

> 
> 
> 
> _________________________________________________________________
> Join the world?s largest e-mail service with MSN Hotmail. 
> http://www.hotmail.com
> 
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org