Skip to content

Instantly share code, notes, and snippets.

@mibmo
Created January 23, 2024 21:55
Show Gist options
  • Save mibmo/8587a973a342610b2322a1e9232a44e3 to your computer and use it in GitHub Desktop.
Save mibmo/8587a973a342610b2322a1e9232a44e3 to your computer and use it in GitHub Desktop.
Print wrapper for halfwidth characters in Python 3
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