https://stackoverflow.com/questions/15352668/download-and-decompress-gzipped-file-in-memory

You need to seek to the beginning of compressedFile after writing to it but before passing it to gzip.GzipFile(). Otherwise it will be read from the end by gzip module and will appear as an empty file to it. See below:

#! /usr/bin/env python
import urllib2
import StringIO
import gzip baseURL = "https://www.kernel.org/pub/linux/docs/man-pages/"
filename = "man-pages-3.34.tar.gz"
outFilePath = "man-pages-3.34.tar" response = urllib2.urlopen(baseURL + filename)
compressedFile = StringIO.StringIO()
compressedFile.write(response.read())
#
# Set the file's current position to the beginning
# of the file so that gzip.GzipFile can read
# its contents from the top.
#
compressedFile.seek(0) decompressedFile = gzip.GzipFile(fileobj=compressedFile, mode='rb') with open(outFilePath, 'w') as outfile:
outfile.write(decompressedFile.read())

https://stackoverflow.com/questions/11914472/stringio-in-python3

download file by python in google colab的更多相关文章

  1. Google Colab 基本操作

    ## 上传 from google.colab import files uploaded = files.upload() for fn in uploaded.keys(): print('Use ...

  2. Google Colab的一些注意事项

    1.执行命令行前面加! 当我们使用python解释器时,我们需要不停地在命令行和IDE 之间切换,当我们需要使用命令行工具时.不过,Jupyter Notebook给了我们在notebook中运行sh ...

  3. Google Colab免费GPU使用教程(一)

    一.前言 现在你可以开发Deep Learning Applications在Google Colaboratory,它自带免费的Tesla K80 GPU.重点是免费.免费!(国内可能需要tz) 这 ...

  4. Google Colab——用谷歌免费GPU跑你的深度学习代码

    Google Colab简介 Google Colaboratory是谷歌开放的一款研究工具,主要用于机器学习的开发和研究.这款工具现在可以免费使用,但是不是永久免费暂时还不确定.Google Col ...

  5. Google Colab使用教程

    简介Google Colaboratory是谷歌开放的云服务平台,提供免费的CPU.GPU和TPU服务器. 目前深度学习在图像和文本上的应用越来越多,不断有新的模型.新的算法获得更好的效果,然而,一方 ...

  6. Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案

    #Python运行Google App Engineer时出现的UnicodeDecodeError错误解决方案   ##问题描述 使用Python2.7.x运行GAE时有时会报这个错误 ```py ...

  7. Google Colab Notebook 的外部文件引用配置

    Google Colab Notebook 的外部文件引用配置 Reference: How to upload the file and read Google Colab 先装工具:google- ...

  8. Google Colab 免费GPU服务器使用教程

    Google免费GPU使用教程(亲测可用)   今天突然看到一篇推文,里面讲解了如何薅资本主义羊毛,即如何免费使用Google免费提供的GPU使用权. 可以免费使用的方式就是通过Google Cola ...

  9. Google免费GPU使用教程(Google Colab Colaboratory)

    参考: https://www.234du.com/1154.html https://mp.weixin.qq.com/s/TGTToLYSQJui94-bQC4HIQ 注册gmail时遇到手机号无 ...

随机推荐

  1. farm

    farm 时间限制:C/C++ 4秒,其他语言8秒 空间限制:C/C++ 262144K,其他语言524288K 64bit IO Format: %lld 题目描述 White Rabbit has ...

  2. springboot收集

    Spring Boot实战:拦截器与过滤器 参考:https://blog.csdn.net/m0_37106742/article/details/64438892 https://www.ibm. ...

  3. zoj 3812 We Need Medicine (dp 状压)

    先贴一下转载的思路和代码,,,:http://blog.csdn.net/qian99/article/details/39138329 状压dp博大精深啊,以后看到n<=50都可以往状压上想, ...

  4. systemtap-note-6-userspace-stack-backtrace

    http://nanxiao.me/systemtap-note-6-userspace-stack-backtrace/

  5. 新建mvc项目

    第一步 第二步 第三步,ok项目建好

  6. UNIDAC如何驱动MSSQL2000

    UNIDAC如何驱动MSSQL2000 如下图,PROVIDER必须设置为PRSQL.默认的PRAUTO,如果操作系统是XP可以,如果是WIN7以上的,不可以. 原因是MSSQL NATIVE 11已 ...

  7. C#中值类型和引用类型的差别浅记

    C#中值类型和引用类型的差别浅记         在C#中,变量的类型分为两种.各自是值类型和引用类型.         值类型的变量直接存储值,说得更详细一些,就是值类型变量在内存中直接存储它们自身 ...

  8. bash 文件头尾插入字符

    头部插入:sed -i '1i\Insert this line' file.txt 尾部插入:echo "hehe"  >> tmp.txt

  9. C++中的sort函数

    (一)为什么要用c++标准库里的排序函数 Sort()函数是c++一种排序方法之一,学会了这种方法也打消我学习c++以来使用的冒泡排序和选择排序所带来的执行效率不高的问题!因为它使用的排序方法是类似于 ...

  10. [Servlet&amp;JSP] 标准标签

    在JSP的规范中提供了一些标准标签(Standard Tag),全部的容器都支持这些标签,它能够协助编写JSP时降低Scriptlet的使用. 全部的标准标签都使用jsp:作为前置.这些标准标签是在J ...