modify files?

Ingo 'resISt' Siebert res1st at
Fri Feb 9 17:17:03 EST 2001

i´m very new to Python but i have to learn that. So i´m starting with litte
programs but i have now a big problem.
I have (Win-)Files which contains something like

fjioejfejfkljklTCHAT "Blablabla" kfoefeisdfidjsfmiosdf...TCHAT "Blablabla"

(tchat are also in low letters)

So i want to replace all Blablabla's with a some chars (i did choose *)
So it should look like

fjioejfejfkljklTCHAT "*********" kfoefeisdfidjsfmiosdf

So I wrote the following Program.

def demorem():
    filea = os.stat('c:/tmp/test.dat')[ST_SIZE]
    print "Filesize:" , filea , "Bytes"
    print "Please wait..."
    f=open('c:/tmp/test.dat', 'r+')
    fpos= int(0)
    while fpos < filea:
        if fstr == 'tchat':
                print "tchat found"
                while fstr2 != ssign :
                    print fstr2, "-> *"
                    if i > 200 :
                        print "Error: someone said too much"
       fpos = fpos+1
 print "Done."

I also use the following at the beginning.

import os, sys
from stat import *

I don´t know if i really need them both, but i will try it later. :)

Now my Problem. If i start my program then it seems that all is working.
"tchat found"
the chars which sould be replaced are listet correct on my screen

tchat found
X -> *
Y -> *

But my file is still the old one, nothing were replaced.
Why does this
nothing do to my file?

And after my program is halted, my Test-File is still in use, said Windows
when i wanted to modify it. Is
also wrong?

It would be great if you could help me.
Ingo Siebert

More information about the Python-list mailing list