How do I display unicode value stored in a string variable using ord()

Chris Angelico rosuav at gmail.com
Thu Aug 16 18:20:15 EDT 2012


On Fri, Aug 17, 2012 at 8:09 AM, Charles Jensen
<hopefullycharles at gmail.com> wrote:
> How would I use ord() to find the unicode value of a string stored in a variable?
>
> So the following 2 lines of code will give me the ascii value of the variable a.  How do I specify ord to give me the unicode value of a?
>
>      a = '…'
>      ord(a)

I presume you're talking about Python 2, because in Python 3 your
string variable is a Unicode string and will behave as you describe
above.

You'll need to look into what the encoding is, and figure it out from there.

ChrisA



More information about the Python-list mailing list