Created
January 23, 2024 21:55
-
-
Save mibmo/8587a973a342610b2322a1e9232a44e3 to your computer and use it in GitHub Desktop.
Print wrapper for halfwidth characters in Python 3
This file contains hidden or 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
def halfwidth(text): | |
wide_map = {i: i + 0xFEE0 for i in range(0x21, 0x7F)} | |
wide_map[0x20] = 0x3000 | |
return text.translate(wide_map) | |
def print_halfwidth(*args, sep=" ", **kwargs): | |
text = sep.join(map(halfwidth, map(str, args))) | |
print(text, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment