veekun / pokedex

more than you ever wanted to know about Pokémon
MIT License
1.44k stars 637 forks source link

Resolve some Python 3 compatability issues with decoding #244

Closed skylar32 closed 6 years ago

skylar32 commented 6 years ago

Python 3 threw a UnicodeDecodeError during table creation— using six to explicitly declare encoding scheme as utf-8 fixes the problem while preserving Python 2 functionality.

encukou commented 6 years ago

Hi, Python 2.6+ includes Python 3's I/O stack. It's just not used by the built-in open. Use from io import open, which is essentially a no-op on Python 3.

magical commented 6 years ago

@encukou I don't think that actually works in this case. There's a comment in load.py that says, # CSV module only works with bytes on 2 and only works with text on 3!.

Python 2.7.13 (default, Jan 12 2017, 17:59:37) 
[GCC 6.3.1 20161221 (Red Hat 6.3.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> import io
>>> w = csv.writer(io.open("/tmp/test", "w", encoding="utf-8"))
>>> w.writerow(["hi"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: write() argument 1 must be unicode, not str
>>> w.writerow([u"hi"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: write() argument 1 must be unicode, not str