Created
March 12, 2025 03:33
-
-
Save chulkilee/7b4d67f2d83117310268834a3b2990b7 to your computer and use it in GitHub Desktop.
Test out different
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess | |
import sys | |
import unicodedata | |
def run_test(val, forms): | |
print("---- print") | |
for form in forms: | |
print(f"{form}\t{unicodedata.normalize(form, val)}") | |
print("\n---- unicode escaped\n") | |
for form in forms: | |
print( | |
f"{form}\t{unicodedata.normalize(form, val).encode('unicode_escape').decode('utf-8')}" | |
) | |
print("\n---- ls -1\n") | |
files = [ | |
{ | |
"filename": unicodedata.normalize(form, f"{form}-{val}.txt"), | |
"content": unicodedata.normalize(form, val) + "\n", | |
} | |
for form in forms | |
] | |
for file in files: | |
with open(file["filename"], "w", encoding="utf-8") as f: | |
f.write(file["content"]) | |
subprocess.run(["ls", "-1"] + [file["filename"] for file in files]) | |
print("\n---- cat\n ") | |
for file in files: | |
print(f"-- {file['filename']}") | |
subprocess.run(["cat", file["filename"]]) | |
for file in files: | |
os.remove(file["filename"]) | |
if __name__ == "__main__": | |
default_val = "\uc548\ub155\ud558\uc138\uc694" # 안녕하세요 | |
forms = ["NFD", "NFKD", "NFC", "NFKC"] | |
val = sys.argv[1] if len(sys.argv) > 1 else default_val | |
run_test(val, forms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment