反正我可以在 Google colaboratory 下载文件吗?

Is there anyway I can download the file in Google colaboratory?

我正在通过此代码实验室在 Google Colaboratory 中尝试 tensorflow, 我需要下载“http://download.tensorflow.org/example_images/flower_photos.tgz”这个文件来完成实验。

如何下载文件。有没有办法上传 tar 文件而不在我的机器上下载它。

我试过这个方法

import urllib
testfile = urllib.URLopener()
testfile.retrieve("http://randomsite.com/file.gz", "file.gz")

这不起作用,也找不到 wget。任何人请告诉我如何做到这一点。

阅读手册,他们有很好的示例和解释:urllib.request

下载:

>>> import os
>>> import urllib.request
>>> urllib.request.urlretrieve('https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', 'google.png')
('google.png', <http.client.HTTPMessage object at 0x7fba3c4cb908>)
>>> os.listdir()
['google.png']

只看内容:

>>> with urllib.request.urlopen('http://www.python.org/') as f:
...     print(f.read(300))

可能更简单:使用!wget,例如,使用以下命令执行单元格:

!wget https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png

会将文件保存到虚拟机的本地文件系统。 (注意前导 !。这是将此行作为 shell 命令执行的信号。)