Using .seek(0) to read.
timr at probo.com
Mon Jan 12 02:59:58 CET 2004
"Amy G" <amy-g-art at cox.net> wrote:
>I got this respnse on a prior post. Peter was correct about not needing to
>compare the old contents, and I was able to easily fix my code by taking out
>However, now I need to open the file in "r+" mode and do a
><filename>.seek(0) on it. I am opening up the .procmailrc file for each
>user in a database that has a "save_junkmail" == 1 and inserting some lines.
>They need to be inserted in the correct spot and each user has a different
>number of lines in their .procmailrc. Everything prints out correctly. I
>now want to write the lines instead of printing to stdout.
You can't easily insert data in the middle of a text file. What you need
to do is create a NEW file, and copy the data from OLD to NEW, adding your
new lines at the appropriate spot. Then close both files, and rename them
os.remove( '.procmailrc.was' )
os.rename( '.procmailrc', '.procmailrc.was' )
os.rename( '.procmailrc.new', '.procmailrc' )
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list