On Tue, Sep 05, 2006 at 06:09:21PM -0700, Guido van Rossum wrote:
> On 9/4/06, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> >--- email database file ---
> > [EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >--- / ---
> >
> > The program opens the file in "r+" mode, reads it line by line and
> >stores the positions of the first character in an every line using tell().
> >When it needs to mark an email it seek()'s to the stored position and write
> >'+' mark so the file looks like
> >
> >--- email database file ---
> >[EMAIL PROTECTED]
> > [EMAIL PROTECTED]
> >--- / ---
>
> I don't understand how it can insert a character into the file without
> rewriting everything after that point.
The essential part of the program is:
results = open("results", "r+")
name, email = getaddresses([to])[0]
while 1:
pos = results.tell()
line = results.readline()
if not line: break
if line.strip() == email:
results.seek(pos)
results.write('+')
break
results.close()
Open the "database" file in "r+" mode, find the email, seek to the
beginning of the line, replace the space with '+'.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED]
Programmers don't die, they just GOSUB without RETURN.
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com