0

I created two arrays with positive and negative emojis by using the emojis' unicode value:

positive = [
u'\U0001F600',
u'\U0001F601',
u'\U0001F602',
u'\U0001F923',
u'\U0001F603',
u'\U0001F604',
u'\U0001F605',
u'\U0001F606',
u'\U0001F609',
u'\U0001F60A',
u'\U0001F60B',
u'\U0001F60E',
u'\U0001F60D',
u'\U0001F618',
u'\U0001F617',
u'\U0001F619',
u'\U0001F61A',
u'\U0000263A',
u'\U0001F642',
u'\U0001F917',
u'\U0001F60F',
u'\U0001F60C',
u'\U0001F61B',
u'\U0001F61C',
u'\U0001F61D',
u'\U0001F924',
u'\U0001F643',
u'\U0001F62C']

negative = [
u'\U0001F610',
u'\U0001F611',
u'\U0001F636',
u'\U0001F644',
u'\U0001F60F',
u'\U0001F623',
u'\U0001F625',
u'\U0001F62E',
u'\U0001F910',
u'\U0001F62F',
u'\U0001F62A',
u'\U0001F62B',
u'\U0001F634',
u'\U0001F612',
u'\U0001F613',
u'\U0001F614',
u'\U0001F615',
u'\U0001F641',
u'\U0001F616',
u'\U0001F61E',
u'\U0001F61F',
u'\U0001F624',
u'\U0001F622',
u'\U0001F62D',
u'\U0001F626',
u'\U0001F627',
u'\U0001F628',
u'\U0001F629',
u'\U0001F630',
u'\U0001F631',
u'\U0001F635',
u'\U0001F621',
u'\U0001F620',
u'\U0001F637',
u'\U0001F912',
u'\U0001F915',
u'\U0001F922',
u'\U0001F927']

But when I print positive[0], for example, I get back this weird character instead of an emoji:

I'm working on an EC2 machine with Amazon Linux and using python-3.4. Same code works as expected from my Macbook.

Daniel Haviv
  • 1,036
  • 8
  • 16

3 Answers3

0

The issue is not a Python Issue. The Mac supports fonts in the terminal that can print those unicode characters.

Those same fonts are not supported in the case you are using.

If the device in question were to support those unicode values they would print properly.

I tested a standard macOS SSH Terminal to Ubuntu and that worked as does native Mac.

Michael Robellard
  • 2,268
  • 15
  • 25
0

Hello Daniel Haviv,

Try this if it works:

print(positive[0].encode('utf-8'))

You can read more here Python 2.x’s Unicode Support

Update: The previous solution did not worked for you try this:

import sys
import codecs
sys.stdout = codecs.getwriter('utf8')(sys.stdout)

print(positive[0])

I found the solution from Setting the correct encoding when piping stdout in Python

Thanos
  • 1,618
  • 4
  • 28
  • 49
0

The issue was I was running under screen

Daniel Haviv
  • 1,036
  • 8
  • 16
  • Hello again Daniel Haviv. Can you also run one more the update code that I have added with screen to check. It would be nice for future reference to know. BR – Thanos Feb 28 '18 at 10:06