sc2reader icon indicating copy to clipboard operation
sc2reader copied to clipboard

printing sc2reader objects in python2 fails on unicode characters

Open jon-n opened this issue 12 years ago • 3 comments

I have a replay where a player has a special character "ó" in his name. When I try to load the replay and call replay.players, it throws an ascii error:

File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/sc2reader/objects.py", line 313, in __repr__
return str(self)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 14: ordinal not in range(128)

On line 313 in objects.py like it mentions, I think this is caused by the str(self) that defaults to the default ASCII encoding.

put a sample replay here with a script: https://github.com/athst/sc2rep-example1

jon-n avatar Oct 20 '13 07:10 jon-n

This is a Python 2/3 problem in handling unicode strings. I'll try to fix it but until then you can create your own string formatting methods for sc2reader objects following python2 conventions.

GraylinKim avatar Oct 21 '13 13:10 GraylinKim

I can't figure out how to make this formatting work in both Python 2 and 3. I don't want to have two versions of every print routine but I don't see another way to do it. I'm going to keep looking but in the meantime anyone affected by this should either upgrade to Python3 (which works) or do the print formatting themselves.

GraylinKim avatar Nov 18 '13 01:11 GraylinKim

Okay, thanks for looking into it.

jon-n avatar Nov 19 '13 05:11 jon-n