Skip to content

Latest commit

 

History

History
50 lines (29 loc) · 1.86 KB

File metadata and controls

50 lines (29 loc) · 1.86 KB



Template request | Bug report | Generate Data Product

Tags: #python #urllib #string #url #convert #library

Author: Florent Ravenel

Description: This notebook will show how to convert a string to a URL using urllib.

References:

Input

Import libraries

import urllib.parse

Setup Variables

  • string: string to be converted to URL
string = "This is a string"

Model

Convert string to URL

The quote() function replaces special characters in the string with their percent-encoded equivalent, which is necessary for URLs. The resulting URL can be used in your Python code or in a web browser.
Note that if you need to convert the URL back to a string, you can use the unquote()

url = urllib.parse.quote(string)

Output

Display result

print(url)