How to Convert a String to URL in Python

Capturing Web addresses inputted by users is a common task when developing Web applications in Python. You store the URL as a string, but need to normalize the address before calling it in a function. For example, the user could have made a typo when entering an address. If you pass this address with a typo or blank space characters in it, your program will not run properly. Luckily, Python contains a built-in module called "urllib" to automatically convert string data into a functional URL.


    • 1

      Open your Python editor.

    • 2


      "import urllib

      input_url = urllib.quote ( ' two.html' ) "

    • 3

      Press "Return."

      In this example, Python loads the urllib module, then takes the string and normalizes the URL by replacing the unreadable blank space in the URL between "example two.html" with the special character "%20".

Related Searches


You May Also Like

Related Ads

Related Searches
View Blog Post

Geek Vs Geek: Windows 10: Should You Want Microsoft’s Next Contentious OS?