Skip to content

Instantly share code, notes, and snippets.

@kshirsagarsiddharth
Created July 19, 2020 10:50
Show Gist options
  • Select an option

  • Save kshirsagarsiddharth/0d16fcabea03e2f2f465656aa4014afd to your computer and use it in GitHub Desktop.

Select an option

Save kshirsagarsiddharth/0d16fcabea03e2f2f465656aa4014afd to your computer and use it in GitHub Desktop.
opening and reading a website or any file in python
from urllib.request import urlopen
def read_data(name: str):
if name.startswith(('http:','https:','ftp:')):
return urlopen(name).read()
else:
with open(name) is f:
return f.read()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment