6

I want to add the Indian Rupee Symbol to a program. This is a non GUI program targeted at Windows and will be run as exe from console. (I would convert it to exe by pyinstaller in the end). I tried using:

print unicode(u"\u20B9")+"12,500"

(As taken from http://www.fileformat.info/info/unicode/char/20b9/index.htm)
It works well in IDLE Interpreter but when I tried running the same code from cmd (Windows 7), it gave error:

Traceback (most recent call last):
  File "D:\My Programs\Projects\StockExchangeSim.py", line 9, in <module>
    print unicode(u"\u20B9")+"12,500"
  File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20b9' in position
 0: character maps to <undefined>

Is there a way to handle this? If there is, will it cause issues when used in other windows computers?

bivo
  • 100
  • 1
  • 2
  • 15
Abhinav
  • 103
  • 2
  • 9

3 Answers3

6
raw_text = u"\u20B9"
print(raw_text)
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
mayank pathak
  • 61
  • 1
  • 2
1

The easiest solution would probably be to avoid trying to print Unicode characters to the windows console. While it does seem possible it would appear to not be trivial to handle in all cases.

Might I suggest the simple solution of

print "12,500 Rupees"
Community
  • 1
  • 1
Tristan Maxson
  • 229
  • 4
  • 15
  • Thanks. I couldn't find that you question you linked because I searched thoroughly for rupee symbol only. – Abhinav Mar 25 '15 at 13:38
1

Inorder to print 'rupay' using python, we can use its respective unicode representation which is '\u20B9' . In order to Print rupay, we just have to do the following:

print(u'\u20B9')

And you will get 'rupay' symbol. It is irrespective of platform (as the question mentioned windows)

P.R.
  • 133
  • 3