Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
utf-8
#8
they want to have characters with high values (e.g. in the big unicode space) converted to utf-8.  they show examples with hexadecimal encoding of integer values for the test characters.  so i would just read the input lines as strings, for each line: split the string into parts, find the part that begins with 'U+'. convert what is after that to an int with int(part[2:],16), encode that into utf-8 bytes, convert the bytes into hex, print out the hex appended to the input line.

something like this untested code:
    for line in sys.stdin:
       tokens = line.split()
       for token in tokens:
           if token[:2].lower() == 'u+':
               utf8 = chr(int(token[2:],16)).encode()
               print(line,' '.join([hex(c).replace('x','')[-2:] for c in utf8]).upper())
in python3, of course
Tradition is peer pressure from dead people

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


Messages In This Thread
utf-8 - by Skaperen - Jun-25-2017, 04:23 AM
RE: utf-8 - by DeaD_EyE - Jun-25-2017, 03:07 PM
RE: utf-8 - by Skaperen - Jun-26-2017, 03:04 AM
RE: utf-8 - by DeaD_EyE - Jun-26-2017, 03:50 AM
RE: utf-8 - by Skaperen - Jun-27-2017, 02:40 AM
RE: utf-8 - by snippsat - Jun-27-2017, 11:16 AM
RE: utf-8 - by DeaD_EyE - Jun-27-2017, 12:05 PM
RE: utf-8 - by Skaperen - Jun-29-2017, 04:19 AM
RE: utf-8 - by snippsat - Jun-29-2017, 05:01 AM

Forum Jump:

User Panel Messages

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