0

I've been looking the answers here in this web site, but nothing have worked so far. The problem is:

In the database, strings are saved like that one: at √s = 7 TeV with.

And the reason is that the "escape" JavaScript function was used.

I was not able to "unescape" these strings in Python yet. I tried to use "eval", "decode", "re.sub" and others, but without success. So please, which function can I use to get it right?

unwind
  • 391,730
  • 64
  • 469
  • 606
Frias
  • 10,991
  • 9
  • 33
  • 40
  • 2
    Please specify in even more detail what you have, and what youl would expect. The quoted string you have no is hard to make sense of. – unwind Feb 28 '11 at 14:46
  • 3
    That string is **not** a product of the JavaScript "escape" function. If it were, there'd be no spaces in it, and the ampersand would be encoded too. – Pointy Feb 28 '11 at 14:51
  • look at here http://stackoverflow.com/questions/628332/decoding-html-entities-with-python – Yuda Prawira Feb 28 '11 at 14:56

2 Answers2

3

The string in question looks like it's encoded with HTML entities, in which case a routine like this one would be appropriate for unescaping. Here's how it looks for your string:

>>> print unescape('at √s = 7 TeV with')
at √s = 7 TeV with
bosmacs
  • 7,341
  • 4
  • 31
  • 31
0

urllib.unquote should undo most if not all of the Javascript escape() function, but specific details on what you're getting out of escape() might help verify this

Daniel DiPaolo
  • 55,313
  • 14
  • 116
  • 115