<type 'unicode'>

Billy Ng kwokng at earthlink.net
Mon May 6 12:11:56 EDT 2002


Thanks guys!  I have one more question.  In the xml doc, I have already
defined

<?xml version='1.0' encoding="UTF-8"?>

How come it still returns me unicode?

Billy Ng

"Peter Hansen" <peter at engcorp.com> wrote in message
news:3CD61492.BD6F207C at engcorp.com...
> Billy Ng wrote:
> >
> > Hi folks,
> >
> > I notice the node.getAttribute() returns the unicode type string.  How
can I
> > cast it to string type?
>
> >>> u = u'string'
> >>> dir(u)
> [..., 'count', 'encode', 'endswith', ... ]
> >>> u.encode('iso-8859-1')
> 'string'
> >>> u.encode('latin-1')
> 'string'
> >>> u.encode('utf-8')
> 'string'
> >>> 'string'.decode('utf-8')
> u'string'
>
> The specific encoding you use is up to you.  If the attribute contains
> only ASCII characters (ordinal value less than 128), any of the above
> should do.
>
> -Peter





More information about the Python-list mailing list