易截截图软件、单文件、免安装、纯绿色、仅160KB

python读写二进制文件

初学python,现在要读一个二进制文件,查找doc只发现file提供了一个read和write函数,而且读写的都是字符串,如果只是读写char等一个字节的还行,要想读写如int,double等多字节数据就不方便了。在网上查到一篇贴子,使用struct模块里面的pack和unpack函数进行读写。下面就自己写代码验证一下。
>>> from struct import *
>>> file = open(r"c:\debug.txt", "wb")
>>> file.write(pack("idh", 12345, 67.89, 15))
>>> file.close() 
接着再将其读进来
>>> file = open(r"c:\debug.txt", "rb")
>>> (a,b,c) = unpack("idh",file.read(8+8+2))
>>> a,b,c
(12345, 67.890000000000001, 15)
>>> print a,b,c
12345 67.89 15
>>> file.close() 
在操作过程中需要注意数据的size


相关文档:

python字典排序

python字典排序
1、 
准备知识:
在python里,字典dictionary是内置的数据类型,是个无序的存储结构,每一元素是key-value对:
如:dict = {‘username’:‘password’,‘database’:‘master’},其中‘username’和& ......

python算法实践7 归并排序

def MergeSort(mylist, low, mid, high):
i = low
j = mid + 1
tmp = []

while i <= mid and j <= high:
if mylist[i] <= mylist[j]:
tmp.append(mylist[i])
i = i + 1
else:
tmp.append(mylist[j])
j = j + 1 ......

Python GTK+ 开发文档

1. Building an Application with PyGTK and Glade
2. Creating a GUI using PyGTK and Glade
3. A Beginner's Guide to Using pyGTK and Glade
4. Is there a walkthrough on getting PyGTK2 and libglade2 to work on win32 ......

python中import自己写的模块

只需要在文件中import与你写的文件的文件名一致的模块名即可,这时python会为你创建一个pyc文件的。
即,如果你已经写了一个名为ssss.py的文件,而现在你需要在名为aaaa.py的文件中使用ssss.py中定义的方法,那么你只需要在aaaa.py中加入import ssss,然后你就可以在aaaa.py中使用ssss.py中的方法(当然方法前需要加模块名 ......

Python学习笔记 模块;文件与文本处理

1.Python中时间函数有几种不同的表示方法。一种是基于数字的表示方法,另外一种是用一系列值来表示,第三种是用ASCII码字符串的可读形式来表示的元组。 time()函数返回的是从某一时间点算起的秒数,该数值是一个浮点数。根据操作系统的不同,这个时间点也不同。通过求localtime(0)的值可以找到系统的该时间点。 localtime ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号