Invalid format character in string

Hal Wine hal_wine at yahoo.com
Fri Apr 4 19:40:31 EST 2003


Nikolai Kirsebom wrote:
> Hi,
> The problems arise where the HTML editor used (to produce the file in
> the first place) has put various expressions of %; and %>.  These are
> HTML codings the creator of the HTML file does not really know about.
> As an example, I've just told them (the users creating the HTML file)
> that they should write the text "%(name)s" where they want the name
> generated and "%(age)s" where they want the age generated.  Then my
> script is run for a set of person objects producing a set of HTML
> files with the correct names and corresponding ages. 

Try replacing those sequences with entries that you add to your 
dictionary to map it back to the original:
   html_in = html_in.replace('%;', '%(_SEMI)s' )  \
                    .replace( '%>;', '%(_SEMI_GT)s')
   dict.update({'_SEMI':'%;', '_SEMI_GT':'%>;'})
   html_out = html_in % dict

--Hal





More information about the Python-list mailing list