If you thought the Web Service example on the about page of Smurl.name was complicated, here's a much simpler version. I use this code on my very own site for the email notifications which will contain long URLs.

Feel free to steal this code into your own projects:


from urllib import urlopen, quote

# variable 'url' is defined elsewhere
if len(url) > 80:
    url = urlopen('http://smurl.name/createSmurl?url=%s' % quote(url)).read()

Was that hard?

Comments

Tim Knapp

No

Your email will never ever be published.

Previous:
Python regular expression tester September 19, 2005 Python
Next:
Ruby and Python benchmarked September 25, 2005 Python
Related by category:
How I run standalone Python in 2025 January 14, 2025 Python
How to resolve a git conflict in poetry.lock February 7, 2020 Python
get in JavaScript is the same as property in Python February 13, 2025 Python
Best practice with retries with requests April 19, 2017 Python
Related by keyword:
parametrize_url() adding parameters to URLs January 14, 2005 Python
Announcing Smurl - a free URL compressor September 7, 2005 Zope