2

I have a Python string "''Grassmere''" as retrieved from a website.

I would like to have the ' displayed as the correct ascii symbol (') but for some reason python insists on just printing the ascii code.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
Chris
  • 21
  • 2

2 Answers2

3

Batteries are included for this one

>>> import xmllib
>>> X=xmllib.XMLParser()
>>> X.translate_references("''Grassmere''")
"''Grassmere''"
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
1

Or without additional modules:

re.sub("&#(\d+);", lambda m: chr(int(m.group(1))), "''Grassmere''")
Eugene Morozov
  • 15,081
  • 3
  • 25
  • 32