Files over the Internet
These days, of course, the file containing the data we want could be on a machine half a world away. Provided the file is accessible over the Internet, though, we can read it just as we do a local file. For example, the Hopedale data not only exists on our computers, but it’s also on a web page. At the time of writing, the URL for the file is http://robjhyndman.com/tsdldata/ecology1/hopedale.dat (you can look at it online!).
(Note that the examples in this section will work only if your computer is actually connected to the Internet.)
Module urllib.request contains a function called urlopen that opens a web page for reading. urlopen returns a file-like object that you can use much as if you were reading a local file. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access