Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What encoding do I need to display a GBP sign (pound sign) using python on cygwin in Windows XP?

I have a python (2.5.4) script which I run in cygwin (in a DOS box on Windows XP). I want to include a pound sign (£) in the output. If I do so, I get this error:

SyntaxError: Non-ASCII character '\xa3' in file dbscan.py on line 253, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

OK. So I looked at that PEP, and now tried adding this to the beginning of my script:

# coding=cp437

That stopped the error, but the output shows ú where it should show £.

I've tried ISO-8859-1 as well, with the same result.

Does anyone know which encoding I need?

Or where I could look to find out?

like image 554
Ben Avatar asked Apr 01 '09 13:04

Ben


2 Answers

The Unicode for a pound sign is 163 (decimal) or A3 in hex, so the following should work regardless of the encoding of your script, as long as the output encoding is working correctly.

print u"\xA3"
like image 115
rjmunro Avatar answered Oct 19 '22 23:10

rjmunro


try the encoding :

# -*- coding: utf-8 -*-

and then to display the '£' sign:

print unichr(163)
like image 37
djibril Avatar answered Oct 20 '22 00:10

djibril