durusmail: qp: What should repr() of an h8 instance give?
What should repr() of an h8 instance give?
2008-01-23
2008-02-04
What should repr() of an h8 instance give?
mario ruggier
2008-02-04
Just a small follow-up on this... while for the one case I was
addressing (that is easily worked around in other ways) it would be
convenient to have eval(repr(h8)) give back the original h8 instance, I
am not convinced myself that this would be what you want in general.
But that is only a suspicion... other insight might help improve
understanding.

But, actually, to make any real sense changing repr(h8) would probably
have to be accompanied with changes to how standard string operations
on h8 behave... changes that would be harder to implement I think. It
seems most standard string operations on an h8 "lose" the class info,
and return a unicode instance... for example:

 >>> from qpy import h8
 >>> s = h8("")
 >>> type(s)

 >>> t = s.replace("m", "n")
 >>> type(t)


Not sure where the bottom of that can of strings would be...

m.


On Jan 23, 2008, at 1:15 PM, mario ruggier wrote:

> Hello!
>
> i stumbled on this when trying to stock away an h8 instance for later
> use, specifically via repr() and then eval(). However doing a repr()
> of an h8 instance gives the same as a repr() of a unicode instance.
> The following interactive session maybe shows this more clearly:
>
> $ python
> Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
> [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from qpy import h8
> >>> x = h8('some xml string')
> >>> x
> u'some xml string'
> >>> repr(x)
> "u'some xml string'"
> >>> y = eval(repr(x))
> >>> y
> u'some xml string'
> >>> y == x
> True
> >>> y.__class__, x.__class__
> (, )
> >>>
>
> What should repr() of an h8 instance give?
>
> mario

reply