[XML-SIG] Problem with xmlproc
mike at skew.org
Wed Dec 21 20:13:15 CET 2005
Marco Meoni wrote:
> i have understood the u operator.
> One question:
> 1)WHY MY CODE PUT THE u OPERATOR IN THE VIDEO OUTPUT?
Fundamentally, an XML document is a sequence of Unicode characters,
independent of any encoding. Therefore, when a the contents of a document or
DTD are being read, it is often very convenient for APIs to use Python's
unicode type as a means of reporting what is in the document. That's why the
unicode objects exist for you. (Although, I would not count on xmlproc to be
consistent about returning unicode).
As for why you see them printed as u'...', that's because you are "print"-ing
tuples and lists that contain unicode objects. If you instead print the
unicode objects individually, rather than their containers, then the unicode
strings will be encoded for you automatically to whatever Python thinks your
screen can handle.
>>> print [u'hello world', u'greetings']
[u'hello world', u'greetings']
>>> print u'hello world'
More information about the XML-SIG