sgmllib parser keeps old tag data?
Berend van Berkum
berend at dotmpe.com
Fri Feb 13 09:51:01 EST 2009
-----BEGIN PGP SIGNED MESSAGE-----
On Fri, Feb 13, 2009 at 02:31:40PM +0000, MRAB wrote:
> Berend van Berkum wrote:
> >import sgmllib
> >class MyParser(sgmllib.SGMLParser):
> > content = ''
> > markup = 
> > span_stack = 
> These are in the _class_ itself, so they will be shared by all its
> instances. You should so something like this instead:
> def __init__(self):
> self.content = ''
> self.markup = 
> self.span_stack = 
Yes.. tested that and SGMLParser won't let me override __init__,
(SGMLParser vars are uninitialized even with sgmllib.SGMLParser(self) call).
Tried some but not the following:
with a differently named init function and one boolean class var 'initialized'
it can check 'if self.initialized' in front of each handler. Does the trick.
Confusion dissolved :)
web, http://dotmpe.com () ASCII Ribbon
email, berend.van.berkum at gmail.com /\
icq, 26727647; irc, berend/mpe at irc.oftc.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
-----END PGP SIGNATURE-----
More information about the Python-list