If I have this line in Python, how to decode it?

s = 'Tara% 2520Stiles% 2520Living'

How to enable it:

Tara Stiles Living 
+6
python encoding
source share
4 answers

Using:

 urllib.unquote(string) 

http://docs.python.org/library/urllib.html

+5
source share

You need to use urllib.unquote , but it seems you need to use it twice:

 >>> import urllib >>> s = 'Tara%2520Stiles%2520Living' >>> urllib.unquote(urllib.unquote(s)) 'Tara Stiles Living' 

After an incorrect request, your "% 2520" turns into "% 20", which without a doubt again turns into "" (space).

+14
source share
 >>> import urllib >>> s = 'Tara%2520Stiles%2520Living' >>> t=urllib.unquote_plus(s) >>> print t Tara%20Stiles%20Living >>> urllib.unquote_plus(t) 'Tara Stiles Living' >>> 
+4
source share
 import urllib s = 'Tara%2520Stiles%2520Living' t='' while s<>t: s,t=t,urllib.unquote(s) 
0
source share

All Articles