Changing HTML file Question

Fredrik Lundh fredrik at pythonware.com
Wed May 14 05:48:39 EDT 2003


Brett Irving wrote:

> Ok I have been trying to use the re subn however it wont run and keeps
> coming up with:
>
>  File "getinput.cgi", line 72, in ?
>     DisplayForm()
>  File "getinput.cgi", line 22, in DisplayForm
>     Display(FormInput)
>  File "getinput.cgi", line 48, in Display
>     Content,TemplateInput)
>  File "/usr/local/lib/python2.2/sre.py", line 151, in subn
>     return _compile(pattern, 0).subn(repl, string, count)
>  File "/usr/local/lib/python2.2/sre.py", line 229, in _compile
>     raise error, v # invalid expression
> sre_constants.error: multiple repeat
>
> I have a function Display(content) which takes in a form from a
> function DisplayForm() as a string and which attempts to replace
> everything that was in that form into a template.html file using:
>
> SubResult = re.subn("<!-- *** INSERT CONTENT HERE *** -->",
>         Content,TemplateInput)
>
> ( I want to change the file where it says INSERT CONTENT HERE)
>
> Can anyone help.

"*" is the RE repeat code.

since you're replacing a constant string, I suggest using string.replace
instead of a regular expression:

    marker = "<!-- *** INSERT CONTENT HERE *** -->")
    page = template.replace(marker, content)

</F>








More information about the Python-list mailing list