Printing Unicode characters and testing

Hi all,

I had to create a program that outputs unicode character \u24A0 (white square) to the command line. It does so by doing print("\u24A0").
image

This works perfectly fine on my computer. Howerver I uploaded my code to GitHub (part of the exercise) and someone downloaded it to try it. When running the code on their computer the following error showed up:

I understand what enconding and decoding means, but I dont know how I could solve this issue and most importantly, how would I test my code for this since on my computer it worked perfectly fine, and had this user not downloaded my code, I wouldn’t have discovered this bug.

Thank you,

Code repo: GitHub - guachilimbo/battleship
Thread where the issue was brought up: Battleship... On command line!

By default they seem to be using a limited encoding cp1252. The issue occurs as this encoding has no character which matches that code point. You can mimic this with:

'\u250a'.encode('cp1252')

The following might be a worthwhile read that explains a bit about unicode and the various supporting encodings for Python:
https://docs.python.org/3/howto/unicode.html

Consider an alternative encoding like utf-8 or a possible fallback character if that’s not available (consider using a less obscure unicode code point). I’m not sure if some of the older terminal options like cmd.exe allows for other encodings (where I assume this error came up). You might need to spend a bit of time looking into it.

Hopefully that explains a little about why the error is thrown but I don’t know how simple the fix would be, sorry. Localisation is a pain.