Python Forum
i thought everything was utf-8 in python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i thought everything was utf-8 in python3
#9
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
Remove these lines dos nothing for Python 3,in Python 3 utf-8 is default.
Quote:UnicodeEncodeError: 'ascii' codec
This 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.
Reply


Messages In This Thread
RE: i thought everything was utf-8 in python3 - by snippsat - Jan-23-2017, 05:43 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 5,049 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE
  Printing from a text file not working as I thought it would PythonZenon 10 6,316 Jun-02-2018, 09:19 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020