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.

2

2 Answers 2

3

Batteries are included for this one

>>> import xmllib
>>> X=xmllib.XMLParser()
>>> X.translate_references("''Grassmere''")
"''Grassmere''"
Sign up to request clarification or add additional context in comments.

Comments

1

Or without additional modules:

re.sub("&#(\d+);", lambda m: chr(int(m.group(1))), "''Grassmere''")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.