<type 'unicode'>
Peter Hansen
peter at engcorp.com
Mon May 6 01:28:50 EDT 2002
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