0

How to print ♠ at terminal where I read string u"\u2660" from data.txt

data = "./data.txt"

with open(data, 'r') as source:
        for info in source: print(info)

u"\u2660" is what I get in the terminal

Om Sao
  • 7,064
  • 2
  • 47
  • 61
  • Possible duplicate of [Process escape sequences in a string in Python](https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python) ? – Alex K. Aug 14 '17 at 10:27

1 Answers1

0

The string u"\u2660" is just a plain text in a txt file. It needs to be interpreted by python interpreter to become a string which represents the unicode character. And you can use eval to do that.

>>> a=r'u"\u2660"'
>>> print(a)
u"\u2660"
>>> b = eval(a)
>>> print(b)
♠
Ray Wang
  • 106
  • 4