Unicode characters not printing correctly in terminal python


Gulib 94

I wrote a very simple program that tells me the unicode value of certain characters.

Here is the program:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

characters = [u'T', u'ב', u'€', u'木', u'♥']

for character in characters:

    print(character + " has the unicode value :\t"+str(hex(ord(character))) + "\n")

It gives the following output:

T has the unicode value :   84

ב has the unicode value :   1489

€ has the unicode value :   8364

木 has the unicode value :   26408

♥ has the unicode value :   9829

I noticed that when I copy and paste here, the output is formatted correctly, but on my computer the second line shows up in the terminal like this

has the unicode value : 1489 ב 

I also tried putting the output into a file and viewing the file with vim, it also looks like this, the characters that should be printed first are printed last. This makes me think it prints correctly but not displays correctly. What could cause this to happen?

kdak

The Unicode LEFT-RIGHT OVERRIDE (LRO) character 0x202D can be used to override the right-justification behavior of Hebrew characters.

characters = [u'T', u'ב', u'€', u'木', u'♥']

for character in characters:

    print(chr(0x202D) + character + " has the unicode value :\t"+str(hex(ord(character))) + "\n")

Provides (on OS X Terminal):

‭T has the unicode value :  0x54

‭ב has the unicode value :  0x5d1

‭€ has the unicode value :  0x20ac

‭木 has the unicode value :  0x6728

♥ has the unicode value :   0x2665

Thanks @guribe94 for figuring out the problem.

You may find the string format easier to read:

    print("%s%s has the unicode value :\t 0x%04x\n" %
        (chr(0x202D), character, ord(character)))

Related


Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Unicode characters not printing correctly in terminal python

Gulib 94 I wrote a very simple program that tells me the unicode value of certain characters. Here is the program: #!/usr/bin/env python3 # -*- coding: utf-8 -*- characters = [u'T', u'ב', u'€', u'木', u'♥'] for character in characters: print(character +

Printing Unicode characters in Python 3.6.5

green frog I'm writing code in Python 3.6.5 using PyDev in Eclipse on Windows. I get an error when running the following line of code: print("•") This is the error I get: SyntaxError: Non-UTF-8 code starting with '\x95' in file C:\Users\short\workspace\Python

Printing Unicode characters in Python 3.6.5

green frog I'm writing code in Python 3.6.5 using PyDev in Eclipse on Windows. I get an error when running the following line of code: print("•") This is the error I get: SyntaxError: Non-UTF-8 code starting with '\x95' in file C:\Users\short\workspace\Python

Printing and writing Unicode characters in Python

Prime Minister I am trying to print out some unicode characters or write them to a text file and am getting an error.. please consult, trying to google gave me some hints but the error is the same.. below is my code.. i may What to do wrong here.. I'm trying t

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

Printing the unicode number of characters in a string (Python)

Hassan Baig This should be simple, but I can't crack it. I have a string of arabic symbols between u'\u0600'- u'\u06FF'and u'\uFB50'- u'\uFEFF'. For example غينيا واستمر العصبة ضرب قد. How to print the unicode number of each character? I am using Python 2.7. s

python - how to write unicode characters to file correctly

yukashima huksay If I run the following code: text = 'سلام عزیزم! عزیزم سلام!' with open('temp.txt', 'w') as out_file: print(text) out_file.write(text) with open('temp.txt', 'r') as in_file: print(in_file.read()) I get the following output: Traceb

python - how to write unicode characters to file correctly

yukashima huksay If I run the following code: text = 'سلام عزیزم! عزیزم سلام!' with open('temp.txt', 'w') as out_file: print(text) out_file.write(text) with open('temp.txt', 'r') as in_file: print(in_file.read()) I get the following output: Traceb

python - how to write unicode characters to file correctly

yukashima huksay If I run the following code: text = 'سلام عزیزم! عزیزم سلام!' with open('temp.txt', 'w') as out_file: print(text) out_file.write(text) with open('temp.txt', 'r') as in_file: print(in_file.read()) I get the following output: Traceb

python - how to write unicode characters to file correctly

yukashima huksay If I run the following code: text = 'سلام عزیزم! عزیزم سلام!' with open('temp.txt', 'w') as out_file: print(text) out_file.write(text) with open('temp.txt', 'r') as in_file: print(in_file.read()) I get the following output: Traceb

python - how to write unicode characters to file correctly

yukashima huksay If I run the following code: text = 'سلام عزیزم! عزیزم سلام!' with open('temp.txt', 'w') as out_file: print(text) out_file.write(text) with open('temp.txt', 'r') as in_file: print(in_file.read()) I get the following output: Traceb

Printing Unicode characters in Poly/ML

Alex Copeland How to print lowercase greek epsilon in SML (using Poly/ML)? I have tried the following: print "ε"; (* Error-unprintable character found in file *) print "\u03B5"; (* Error-Conversion exception (Invalid string constant) raised while converting \u

Printing wide Unicode characters with ncurses

Luke Collins I'm trying to locate an asterisk Unicode character on the screen using a library in ncurses.hC on Ubuntu . The code I am trying to run is as follows: #include <stdio.h> #include <wchar.h> #include <curses.h> #include <ncurses.h> #include <stdlib.h

Printing Unicode characters in Poly/ML

Alex Copeland How to print lowercase greek epsilon in SML (using Poly/ML)? I have tried the following: print "ε"; (* Error-unprintable character found in file *) print "\u03B5"; (* Error-Conversion exception (Invalid string constant) raised while converting \u