On Sun, Sep 03, 2006 at 01:45:28PM -0700, Aahz wrote: > On Sun, Sep 03, 2006, Marcin 'Qrczak' Kowalczyk wrote: > > "tomer filiba" <[EMAIL PROTECTED]> writes: > >> > >> file("foo", "w+") ? > > > > What is a rationale of this operation for a text file? > > You want to be able to read the file and write data to it. That argues > in favor of seek(0) and seek(-1) being the only supported behaviors, > though.
Sometimes programs need tell() + seek(). Two examples (very similar, really). Example 1. I have a program, an email robot that receives email(s) and marks email addresses in a "database" that is actually a text file: --- 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] --- / --- Example 2. INN (the NNTP daemon) stores (at least stored when I was using it) information about newsgroup in a text file database. It uses another approach - it stores info using lines of equal length: --- newsgroups --- comp.lang.python 000001234567 comp.lang.python.announce 000000abcdef --- / --- Probably INN doesn't use tell() - it just calculates the position using line length. But a python program needs tell() and seek() for such a file. Oleg. -- Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com