changing some lines in a file

Peter Posselt Vestergaard posselt at daimi.au.dk
Tue Jul 6 08:44:35 EDT 1999


Hi, I'm quite a newbie in Python-programming, so I hope you'll forgive
me asking about some pretty things. :-)
My problem is that I have a file in which i want to find some lines and
replace them with some other data. I've tried a lot of things but
nothing seems to work.
Below is my best try, but it seems that the script stops when it is
about to execute the line:

line=('fi='+Form["fi"].value)

I'll be thankfull for any kind of help.
Best regards

Peter Vestergaard

------------------------------------------------------------------


db = open("db.dat","r+")						 
data = db.readlines()
db.close

found=0
for line in data:
    print found
    if found==1:
        if line[0:2]=='fi':
            line=('fi='+Form["fi"].value)
        elif line[0:2]=='la':
            line='la='+Form["la"].value
        elif line[0:2]=='em':
            line='em='+Form["em"].value
        elif line[0:2]=='ho':
            line='ho='+Form["ho"].value
        elif line[0:2]=='st':
            line='st='+Form["st"].value
            found=2
    if line[0:9]==('id='+Form["id"].value):
        found=1
if found==0:
    print '<H1>Fejl i årskortnummeret!</H1>'
    stop 

db = open("db.dat","w")
db.writelines(data)
db.close




More information about the Python-list mailing list