Article 6F5FG Cross-platform way to enter Unicode characters

Cross-platform way to enter Unicode characters

by
John
from John D. Cook on (#6F5FG)

The previous post describes the hoops I jumped through to enter Unicode characters on a Mac. Here's a script to run from the command line that will copy Unicode characters to the system clipboard. It runs anywhere the Python module pyperclip runs.

 #!/usr/bin/env python3 import sys import pyperclip cp = sys.argv[1] ch = eval(f"chr(0x{cp})") print(ch) pyperclip.copy(ch)

I called this script U so I could type

 U 03c0

at the command line, for example, it would print to the command line and also copy it to the clipboard.

Unlike the MacOS solution in the previous post, this works for any Unicode value, i.e. for code points above FFFF.

On my Linux box I had to install xclip before pyperclip would work.

The post Cross-platform way to enter Unicode characters first appeared on John D. Cook.
External Content
Source RSS or Atom Feed
Feed Location http://feeds.feedburner.com/TheEndeavour?format=xml
Feed Title John D. Cook
Feed Link https://www.johndcook.com/blog
Reply 0 comments