Created
July 19, 2020 10:50
-
-
Save kshirsagarsiddharth/0d16fcabea03e2f2f465656aa4014afd to your computer and use it in GitHub Desktop.
opening and reading a website or any file in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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