#🔒 Unicode 16.0 and 15.1 Characters in Python

11 messages · Page 1 of 1 (latest)

tardy torrent
#

Hello, i'am trying to generated all unicode 16.0 characters on a file and all unicode 15.1 characters on a other file and display on a new file the added characters on unicode 16.0. I tried this code, but this is not what im looking for, because there may be new emojis or others characters that may not be displayed on unicode 15.1 but is on unicode 16.0 and i dont think ive generated characters correctly. Please take a look on the source code, thank you.

import os

file_15_1 = "unicode_15_1.txt"
file_16_0 = "unicode_16_0.txt"
file_new_in_16_0 = "new_in_16_0.txt"

unicode_15_1_end = 149813
unicode_16_0_end = 154998 

def is_visible(char):
    return char.isprintable() and not char.isspace() and char != ""

def generate_unicode_file(start, end, filename):
    with open(filename, "w", encoding="utf-8") as f:
        for codepoint in range(start, end + 1):
            try:
                f.write(chr(codepoint) + "\n")
            except ValueError:
                continue

generate_unicode_file(0, unicode_15_1_end, file_15_1)
generate_unicode_file(0, unicode_16_0_end, file_16_0)

def find_new_characters(file1, file2, output_file):
    with open(file1, "r", encoding="utf-8") as f1, open(file2, "r", encoding="utf-8") as f2:
        chars_15_1 = set(f1.read().splitlines())  
        chars_16_0 = set(f2.read().splitlines())  
        new_in_16_0 = chars_16_0 - chars_15_1   

    with open(output_file, "w", encoding="utf-8") as f_out:
        for char in sorted(new_in_16_0):
            if is_visible(char): 
                f_out.write(char + "\n")

        for char in sorted(new_in_16_0):
            if not is_visible(char):  
                f_out.write(f"U+{ord(char):04X}\n") 


find_new_characters(file_15_1, file_16_0, file_new_in_16_0)

print("Fichiers générés :")
print(f"- {file_15_1}")
print(f"- {file_16_0}")
print(f"- {file_new_in_16_0}")```
hollow kelpBOT
#

@tardy torrent

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

spark fjord
#

can you reproduce the issue in a smaller portable code basically simplifying the code and issue?

#

for others to read as it's bedtime

tardy torrent
#

and the code is not that hard to understand tbh

silver brook
#

@tardy torrent The code looks ok to me, assuming the unicode end points are correct. (Though char != "" is always true, you probably meant " ", a space?)

What's not right about what you're getting?

#

I'd want to print whatever errors you're getting here:

            try:
                f.write(chr(codepoint) + "\n")
            except ValueError:
                continue

instead of silently throwing them away - you need to understand what's not good here.

hollow kelpBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.