Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python 2 Unicode question
#1
when using the Unicode type in Python 2, what are the ord() and chr() like functions to convert to the numeric values of the characters and back? ok, ord() works but chr() is limited to values less than 256. or do i need to do this:
def uchr(u):
    return eval("u'\\u"+hex(u+2**24)[-max(len(hex(u))-2,4):]+"'")
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Doesn't builtin unichr() fit your needs?
Reply
#3
i'll try that one. i only have Python 3 docs handy, so i was guessing the names. i should have looked at sit(__builtins__).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  unicode question DPaul 5 2,424 Jun-19-2020, 03:06 PM
Last Post: DPaul
  python-resize-image unicode decode error Pedroski55 3 3,401 Apr-21-2020, 10:56 AM
Last Post: Pedroski55
  [split] how to print unicode in python? Frank57 4 2,963 Oct-28-2019, 08:57 PM
Last Post: Frank57
  clean unicode string to contain only characters from some unicode blocks gmarcon 2 3,918 Nov-23-2018, 09:17 PM
Last Post: Gribouillis
  how to print unicode in python? Skaperen 1 6,155 Jan-24-2017, 05:36 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020