本文介绍了无论如何,我可以在Google colaboratory中下载文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在此代码实验室中尝试Google合作实验室中的tensorflow,我需要下载' http://download.tensorflow.org/example_images/flower_photos.tgz此文件即可完成实验.

I am trying tensorflow in Google Colaboratory from this codelab,I need to download 'http://download.tensorflow.org/example_images/flower_photos.tgz' this file to complete the lab.

如何下​​载文件.无论如何,有没有上传tar文件而不将其下载到我的计算机上.

How I can download the file. Is there anyway to upload the tar file without downloading it on my machine.

我尝试过这种方法

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

这不起作用,也找不到wget.有人请告诉我该怎么做.

This doesn't work, wget is not found also. Anyone please tell me how to do this.

推荐答案

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

Read the manual, they have good examples and explanations: 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))

这篇关于无论如何,我可以在Google colaboratory中下载文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 09:32