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("<xml/>")
>>> type(s)
<type 'qpy.c8.h8'>
>>> t = s.replace("m", "n")
>>> type(t)
<type 'unicode'>

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('<xml>some xml string</xml>')
>>> x
u'<xml>some xml string</xml>'
>>> repr(x)
"u'<xml>some xml string</xml>'"
>>> y = eval(repr(x))
>>> y
u'<xml>some xml string</xml>'
>>> y == x
True
>>> y.__class__, x.__class__
(<type 'unicode'>, <type 'qpy.c8.h8'>)
>>>

What should repr() of an h8 instance give?

mario

_______________________________________________
QP mailing list
[email protected]
http://mail.mems-exchange.org/mailman/listinfo/qp

Reply via email to