Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > String to unicode - duplicating by function the effect of u prefix

Reply
Thread Tools

String to unicode - duplicating by function the effect of u prefix

 
 
CiTro
Guest
Posts: n/a
 
      06-18-2009
I'm looking for a way to convert a string to it's unicode "brother".

This means:

stringOne = "\u0026"
stringTwo = u"\u0026"

print unicode(stringOne) == stringTwo

The result is false. What function should I use, to duplicate the
effect of the "u" prefix ?
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      06-18-2009
CiTro wrote:

> I'm looking for a way to convert a string to it's unicode "brother".
>
> This means:
>
> stringOne = "\u0026"
> stringTwo = u"\u0026"
>
> print unicode(stringOne) == stringTwo
>
> The result is false. What function should I use, to duplicate the
> effect of the "u" prefix ?


"\u..." has a special meaning only in unicode, not string literals:

>>> s = "\u0026"
>>> len(s)

6
>>> s.decode("unicode-escape")

u'&'
>>> _ == u"\u0026"

True

Peter

 
Reply With Quote
 
 
 
 
CiTro
Guest
Posts: n/a
 
      06-18-2009
Thank you, Peter. That solved my problem.
 
Reply With Quote
 
Vincent
Guest
Posts: n/a
 
      06-18-2009
On Jun 18, 3:23*pm, CiTro <(E-Mail Removed)> wrote:
> Thank you, Peter. That solved my problem.


the another way is,

codecs.raw_unicode_escape_decode(stringOne) == stringTwo

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
duplicating characters in a string Adam Akhtar Ruby 29 03-12-2008 03:38 PM
removing a namespace prefix and removing all attributes not in that same prefix Chris Chiasson XML 6 11-14-2006 05:08 PM
Duplicating a string? gao_bolin@voila.fr Perl Misc 2 06-17-2005 11:29 AM
"static" prefix - to parallel "this" prefix Tim Tyler Java 36 12-10-2004 01:02 AM
unicode string literals and "u" prefix nico Python 6 11-10-2004 09:14 AM



Advertisments