Skip to main content

Posts

Showing posts from March, 2017

Python: How to Unescape String (DecodeURI in JavaScript)

We can use urllib module to do this. Oh and by the way, this is on Python 2.7x and Python 3+. #!/usr/bin/env python2 """urllib module - Python 2.7x""" import urllib # ENCODED STRING THE_ENCODED_STRING = "https%3A%2F%2Flalala.com%2Flalala%3Fla%3Dla%26lala%3Dlala" # DECODED STRING THE_DECODED_STRING = urllib.unquote(THE_ENCODED_STRING) print(THE_DECODED_STRING) """ Python 3+ """ import urllib.parse # ENCODED STRING THE_ENCODED_STRING = "https%3A%2F%2Flalala.com%2Flalala%3Fla%3Dla%26lala%3Dlala" # DECODED STRING THE_DECODED_STRING = urllib.parse.unquote(THE_ENCODED_STRING) print(THE_DECODED_STRING) This is the documentation for urllib.unquote Python 2 utility . This is the documentation for urllib.parse.unquote Python 3 utility . The opposite of that function is urllib.quote(string) (Python 2) with additional argument to create a custom safe characters list. This is the documentation . ...