# -*- coding: utf-8 -*- from __future__ import division, print_function, unicode_literalsRemove these lines dos nothing for Python 3,in Python 3 utf-8 is default.
Quote:UnicodeEncodeError: 'ascii' codecThis is just strange that python
print()
give this error.Now do you run trough shell with
sys.argv
,so that can maybe cause it.There are some not so god stuff in your code.
word_file_name = '/usr/share/dict/american-english'
Should not be in global namespace,but be given as an argument to the function.
def main( args ):
Argument
args
is not used in function?Quote:it turns out print() will work if i do print( word.encode() )Make no sense that you should convert back to bytes to print it.
Test online and see if work repel.it.
Shell test,i don't have Linux with Python 3 available now,but command should be the same.
C:\ λ which python /c/python36/python C:\ λ python -c "import sys; print(sys.stdout.encoding)" utf-8 C:\ λ python -c "print('1053:Asunción')" 1053:Asunción C:\ λ python -c "print('Spicy jalapeño ☂')" Spicy jalapeño ☂
Quote:does anyone know why strings (as opposed to bytes) and utf-8 do not play well together in python 3?They make sure(a very important design) to not mix bytes and string,
it would have been terrible(back to Python 2) if they work together.
Now is string characters of Unicode.