[Tutor] To write data in two different fonts?

prasad rao prasadaraon50 at gmail.com
Wed Aug 12 16:24:38 CEST 2009


> >xml.sax.saxutils.escape(/data/[, /entities/])
>
> >  Escape '&', '<', and '>' in a string of data.
>
>  > You can escape other strings of data by passing a dictionary as the
>   >optional /entities/ parameter. The keys and values must all be
>   >strings; each key will be replaced with its corresponding value. The
>   >characters '&', '<' and '>' are always escaped, even if /entities/
>   >is provided.
>
> >Let us know if that doesn't do the trick.
>
> >DaveA


Thank you Dave

         It is working perfectly with the modifications you suggested.

    <code>


def sc(adir):
        entities = {'&' : '&amp;',
           '<' : '&lt;',
           '>' : '&gt;',
           '"' : '&quot;',
           "'" : '&apos;'}

        import os,myfiles,xml.sax.saxutils
        dest=open('C:/scripts.html','w')
        s=myfiles.myfiles(adir)
        dest.write('<html>')
        for x in s:
              if os.path.isfile(x):
                   sorce=open(x,'r')

                   dest.write('<h1><font=Helvetica,fontsize=14>')
                   dest.write(x)
                   dest.write('</h1><pre>')


                   for l in sorce:
                        l=xml.sax.saxutils.escape(l,entities)
                        dest.write('<font=Arial,fontsize=8>')
                        dest.write(l)
                   dest.write('<pre>')
                   sorce.close()
              else:pass
        dest.write('</html>')
        dest.close()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090812/e40d892f/attachment-0001.htm>


More information about the Tutor mailing list