chunk模块用于读取TIFF格式的文件,打开应该使用二进制模式

TIFF 标签图像文件格式

import chunk

import chunk 

f=open('E:\\test.tiff','rb') 

print(type(f)) 

html=chunk.Chunk(f) 

print(html.getname()) 

print(html.getsize())

help('chunk')

Help on module chunk:

NAME

chunk - Simple class to read IFF chunks.

DESCRIPTION

An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File

Format)) has the following structure:

+----------------+

| ID (4 bytes)   |

+----------------+

| size (4 bytes) |

+----------------+

| data           |

| ...            |

+----------------+

The ID is a 4-byte string which identifies the type of chunk.

The size field (a 32-bit value, encoded using big-endian byte order)

gives the size of the whole chunk, including the 8-byte header.

Usually an IFF-type file consists of one or more chunks.  The proposed

usage of the Chunk class defined here is to instantiate an instance at

the start of each chunk and read from the instance until it reaches

the end, after which a new instance can be instantiated.  At the end

of the file, creating a new instance will fail with an EOFError

exception.

Usage:

while True:

try:

chunk = Chunk(file)

except EOFError:

break

chunktype = chunk.getname()

while True:

data = chunk.read(nbytes)

if not data:

pass

# do something with data

The interface is file-like.  The implemented methods are:

read, close, seek, tell, isatty.

Extra methods are: skip() (called by close, skips to the end of the chunk),

getname() (returns the name (ID) of the chunk)

The __init__ method has one required argument, a file-like object

(including a chunk instance), and one optional argument, a flag which

specifies whether or not chunks are aligned on 2-byte boundaries.  The

default is 1, i.e. aligned.

CLASSES

builtins.object

Chunk

class Chunk(builtins.object)

|  Methods defined here:

|

|  __init__(self, file, align=True, bigendian=True, inclheader=False)

|      Initialize self.  See help(type(self)) for accurate signature.

|

|  close(self)

|

|  getname(self)

|      Return the name (ID) of the current chunk.

|

|  getsize(self)

|      Return the size of the current chunk.

|

|  isatty(self)

|

|  read(self, size=-1)

|      Read at most size bytes from the chunk.

|      If size is omitted or negative, read until the end

|      of the chunk.

|

|  seek(self, pos, whence=0)

|      Seek to specified position into the chunk.

|      Default position is 0 (start of chunk).

|      If the file is not seekable, this will result in an error.

|

|  skip(self)

|      Skip the rest of the chunk.

|      If you are not interested in the contents of the chunk,

|      this method should be called so that the file points to

|      the start of the next chunk.

|

|  tell(self)

|

|  ----------------------------------------------------------------------

|  Data descriptors defined here:

|

|  __dict__

|      dictionary for instance variables (if defined)

|

|  __weakref__

|      list of weak references to the object (if defined)

FILE

c:\python3.5\lib\chunk.py

 
 
摘自:
https://www.cnblogs.com/dengyg200891/p/4947685.html
 

python chunk模块的更多相关文章

  1. python之模块chunk,了解即可

    # -*- coding: utf-8 -*-#python 27#xiaodeng#python之模块chunk# chunk模块专用于读取TIFF格式的文件,打开应当使用二进制模式 #TIFF:标 ...

  2. Python标准模块--threading

    1 模块简介 threading模块在Python1.5.2中首次引入,是低级thread模块的一个增强版.threading模块让线程使用起来更加容易,允许程序同一时间运行多个操作. 不过请注意,P ...

  3. Python的模块引用和查找路径

    模块间相互独立相互引用是任何一种编程语言的基础能力.对于“模块”这个词在各种编程语言中或许是不同的,但我们可以简单认为一个程序文件是一个模块,文件里包含了类或者方法的定义.对于编译型的语言,比如C#中 ...

  4. Python Logging模块的简单使用

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

  5. Python标准模块--logging

    1 logging模块简介 logging模块是Python内置的标准模块,主要用于输出运行日志,可以设置输出日志的等级.日志保存路径.日志文件回滚等:相比print,具备如下优点: 可以通过设置不同 ...

  6. python基础-模块

    一.模块介绍                                                                                              ...

  7. python 安装模块

    python安装模块的方法很多,在此仅介绍一种,不需要安装其他附带的pip等,python安装完之后,配置环境变量,我由于中英文分号原因,环境变量始终没能配置成功汗. 1:下载模块的压缩文件解压到任意 ...

  8. python Queue模块

    先看一个很简单的例子 #coding:utf8 import Queue #queue是队列的意思 q=Queue.Queue(maxsize=10) #创建一个queue对象 for i in ra ...

  9. python logging模块可能会令人困惑的地方

    python logging模块主要是python提供的通用日志系统,使用的方法其实挺简单的,这块就不多介绍.下面主要会讲到在使用python logging模块的时候,涉及到多个python文件的调 ...

随机推荐

  1. Yii2 使用json 和设置component 中'format' => yii\web\Response::FORMAT_JSON 的区别

    在Yii2中如果设置了 'response' => [  'format' => yii\web\Response::FORMAT_JSON,  'charset' => 'UTF- ...

  2. JPA的锁机制

    JPA 各种实体锁模式的区别 字数2084 阅读304 评论0 喜欢4 为了能够同步访问实体,JPA提供了2种锁机制.这两种机制都可以避免两个事务中的其中一个,在不知情的情况下覆盖另一个事务的数据. ...

  3. Docker 学习应用篇之二: Docker的介绍和安装

    之前说过Docker的好处,Docker可以集装箱化的部署应用程序.那么Docker是通过什么实现的呢.要理解Docker内部构建,需要先理解Docker的四种部件 1)images:镜像,docke ...

  4. Solr学习笔记之问题汇总

    一. 问题描述:Solr在建立索引时候出现如下错误:org.apache.solr.common.SolrException: Document [null] missing required fie ...

  5. MTU-TCP/IP协议栈-linux kernel-TCP丢包重传-UDP高性能-AI- ip数据报 tcp数据报

    1.IP协议首部 TCP报文段的首部  UDP分组结构   ip数据报 tcp数据报 UDP校验 w 报文长度该字段指定UDP报头和数据总共占用的长度.可能的最小长度是8字节,因为UDP报头已经占用了 ...

  6. 添加用户username到sudo组

    添加用户username到sudo组: usermod -aG sudo username USERMOD(8) 系统管理命令 USERMOD(8) 名 usermod - 修改一个用户账户 大 us ...

  7. GET、POST编码问题

    GET请求.POST经常会出现中文乱码的问题,最好约定前后端的编码,一般为UTF-8.但是这里面也是有坑的. 后端设置编码为UTF-8的推荐方式: SpringMVC配置过滤器: <filter ...

  8. 洛谷P4035 球形空间产生器 [JSOI2008] 高斯消元

    正解:高斯消元 解题报告: 链接! 昂开始看到以为是,高斯消元板子题? 开始很容易想到的是,虽然是多维但是可以类比二维三维列出式子嘛 但是高斯消元是只能处理一元问题的啊,,,辣怎么处理呢 对的这就是这 ...

  9. python2.X编码

    1.Python文件的编码 在Python文件中,可以在第一或第二行指定文件的编码格式(以注释的形式加),这也是Python语法规定的,见http://www.python.org/peps/pep- ...

  10. Animator Override Controller学习及性能测试

    本文由博主(YinaPan)原创,转载请注明出处: http://www.cnblogs.com/xsln/p/Animator_Override_Controller.html 一.Animator ...