>
> basically I took the idea and the code example given and wrote this 
> little function, i stuck vars in this html page like #email# and 
> just used it like this, " insertdata('#email#','[EMAIL PROTECTED]')
>
> works perfect!

ARe you sure? The problem using seek and write is that if the data
you are inserting is bigger than your marker you will overwrite the
data following the marker.

Thus if your marker were in a table like:


<TR><TD>#email#</TD><TD>Scott's email</TD></TR>

And you overwrite the #mail# with [EMAIL PROTECTED]

You will end up with:

<TR><TD>[EMAIL PROTECTED]'s email</TD></TR>


Which will not display the way you want!

> def insertdata(name, data):
>    file = open('template.html', 'r+')
>    contents = file.read()
>    pos = contents.index(name)
>    file.seek(pos)
>    file.write(data)

This does not insert it overwrites.
You are better to insert the content into contents and
then just write it all back to the file in one move.

>    file.write(contents[pos + len(name):])
>    file.close()


HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to