from urllib.parse import urljoin
from urllib.request import pathname2url
file_path = r"C:\Users\UserName\Desktop\example.xlsx"
file_url = urljoin("file:", pathname2url(file_path))
print(file_url)
# file:///C:/Users/UserName/Desktop/example.xlsx
Go to list of users who liked
from urllib.parse import urljoin
from urllib.request import pathname2url
file_path = r"C:\Users\UserName\Desktop\example.xlsx"
file_url = urljoin("file:", pathname2url(file_path))
print(file_url)
# file:///C:/Users/UserName/Desktop/example.xlsx
Register as a new user and use Qiita more conveniently
Go to list of users who liked