Read and Write the same file

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue May 1 19:24:54 EDT 2007


En Tue, 01 May 2007 20:03:28 -0300, JonathanB <doulos05 at gmail.com>  
escribió:

> Ok, so this is the scenario. I need to create a simple, no-frills XML
> editor for non-technical users. It doesn't have to do anything fancy,
> what I want is a series of text boxes with the text contents of the
> elements pre-printed. Then the users can type their changes into the
> text boxes and click submit and it will load the changes in. So here
> is the problem, this means I need to open the same file as both read
> and write. How do I do this? I'm slowly learning the DOM stuff that I
> need to know to do this, but this file thing I haven't been able to
> find anywhere.

Open the file for reading; read and parse the document; close the file.
Build form and show to the user.
Get data after user clicks OK.
Build document, open file for writing, write document, close file.

Reading and writing happen on two separate stages, and you dont have to  
keep the file open all the time.

-- 
Gabriel Genellina



More information about the Python-list mailing list