Jan-23-2017, 05:00 AM
i made a little test program to start exploring utf-8, testutf.py:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import division, print_function, unicode_literals word = '\x41\x73\x75\x6e\x63\x69\xc3\xb3\x6e' rword = repr(word) print( rword )running it i get:
Output:lt1/forums /home/forums 19> py2 testutf.py
u'Asunci\xc3\xb3n'
lt1/forums /home/forums 20> py3 testutf.py
Traceback (most recent call last):
File "testutf.py", line 6, in <module>
print( rword )
UnicodeEncodeError: 'ascii' codec can't encode characters in position 7-8: ordinal not in range(128)
lt1/forums /home/forums 21> cat testutf.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
word = '\x41\x73\x75\x6e\x63\x69\xc3\xb3\x6e'
rword = repr(word)
print( rword )
lt1/forums /home/forums 22> ls -l testutf.py
-rw-r--r-- 1 forums forums 193 Jan 22 23:40 testutf.py
lt1/forums /home/forums 23> md5sum testutf.py
27e2a0797beaaf93daf84c8eb2323d02 testutf.py
lt1/forums /home/forums 24>
if i add on .encoding() then i get this:Output:lt1/forums /home/forums 26> md5sum testutf.py
ac5ca2295d64a26ff249a4afad161a79 testutf.py
lt1/forums /home/forums 27> ls -l testutf.py
-rw-r--r-- 1 forums forums 202 Jan 22 23:54 testutf.py
lt1/forums /home/forums 28> cat testutf.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import division, print_function, unicode_literals
word = '\x41\x73\x75\x6e\x63\x69\xc3\xb3\x6e'
rword = repr(word)
print( rword.encode() )
lt1/forums /home/forums 29> py3 testutf.py
b"'Asunci\xc3\x83\xc2\xb3n'"
lt1/forums /home/forums 30> py2 testutf.py
u'Asunci\xc3\xb3n'
lt1/forums /home/forums 31>
now what do i need to do to output utf-8 characters to my terminal without the b'' or u'' additions?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.