Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print rupee symbol in Windows console using Python?

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?

like image 902
Abhinav Avatar asked Mar 25 '15 10:03

Abhinav


People also ask

How do you print symbols in python?

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.

How do I type ₹ on Windows?

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 (₹).

How do you make an INR symbol?

The Indian rupee sign (₹) is the currency symbol for the Indian rupee (ISO 4217: INR), the official currency of India.


3 Answers

raw_text = u"\u20B9"
print(raw_text)
like image 150
mayank pathak Avatar answered Oct 03 '22 01:10

mayank pathak


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"
like image 39
Tristan Maxson Avatar answered Oct 03 '22 01:10

Tristan Maxson


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)

like image 27
P.R. Avatar answered Oct 03 '22 01:10

P.R.