Dyalog / dyalog-jupyter-kernel

A Jupyter kernel for Dyalog APL
https://dyalog.github.io/dyalog-jupyter-kernel/
MIT License
64 stars 20 forks source link

Kernel doesn't work in non-UTF-8 locales #56

Open jayfoad opened 5 years ago

jayfoad commented 5 years ago

If you run the kernel in a non-UTF-8 locale, e.g. by setting LANG=C, it (sometimes) fails to output APL characters with an error message like: 'ascii' codec can't encode characters in position 39-55: ordinal not in range(128)

jayfoad commented 5 years ago

The usual advice is to fix your locale or override it, e.g. with one of:

LANG=C.UTF-8 # force UTF-8 locale
PYTHONIOENCODING=UTF-8 # tell Python to use UTF-8 for io streams
PYTHONIOENCODING=:replace # tell Python to replace characters it can't encode with '?'
PYTHONUTF8=1 # tell Python to use UTF-8 for io streams

Alternatively we could try to fix the troublesome print statement with something like:

e = locale.getpreferredencoding(False)
print(s.encode(e, 'replace').decode(e))

But I'm not sure if it's worth it.