Python Forum
a better way to code this to fix a URL?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
a better way to code this to fix a URL?
#3
If the url should always start with https even, if only a hostname is given, you could use this:

from urllib.parse import urlsplit, urlunsplit


def conv2(url):
    return urlunsplit(("https", *urlsplit(url)[1:]))
But I would prefer an error message, that this scheme is not supported or that the url is mistyped.
Automatic correction of human input, leads to funny outcomes.

And sometimes gene sequences are also renamed because Excel has interpreted the text input and turned the name into a date.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: a better way to code this to fix a URL? - by DeaD_EyE - Mar-19-2024, 09:15 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020