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?
To print any character in the Python interpreter, use a \u to denote a unicode character and then follow with the character code. For instance, the code for β is 03B2, so to print β the command is print('\u03B2') . There are a couple of special characters that will combine symbols.
Type 20B9 and then press ALT + x keys. As soon as you press this key combination, the text 20B9 will be replaced by the Indian currency's new Rupee symbol (₹).
The Indian rupee sign (₹) is the currency symbol for the Indian rupee (ISO 4217: INR), the official currency of India.
raw_text = u"\u20B9"
print(raw_text)
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"
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With