how can I subclass a string (str)?

Mark McEahern marklists at mceahern.com
Tue Aug 13 14:38:40 EDT 2002


[Martin v. Lowis]
> "Matt Gerrans" <matt_gerrans at hp.com> writes:
>
> > class mystr(str):
> >    def HexRepr(self):
> >       print 'A hex on ye!'
>
> Sure - but what if you want to refer to the internal representation as
> well?

I think he meant:

class mystr(str):

  def HexRepr(self):
    return hex(self)

Of course, hex("foo") fails, but you get the idear.  And if you do, kindly
explain it to me, because I sure as hell don't.  ;-)

// m

-





More information about the Python-list mailing list