为什么Python、PyS60的md5模块的计算结果不同
对于一个0字节文件md5值的计算结果:
python 2ad97987fef63cd17a0670a1d1c33beb
pys60 49e3c236428e806446085b31ad0afcdf
然而,用WinMD5:
winmd5 d41d8cd98f00b204e9800998ecf8427e
谁能告诉我这是为什么?
附上我的python代码:
import md5
j=md5.md5()
j.update(u'F:\\blank.txt')
print j.hexdigest()
还有,python, pys60的计算时间极短,在我手机里46.9MB的文件算30000次用时1.4s(手机CPU369MHz),而用WinMD5的话,需要几十秒钟,这是为什么?
j.update(u'F:\\blank.txt') 是去算字串面值,不是开文件来算...
WinMD5 是算 md5sum 的吧,
如果文件大点,python md5 就不能一次update
python 已经有md5sum.py
Python-2.6.4/Tools/scripts/md5sum.py
Python-3.1.1/Tools/scripts/md5sum.py
pys60 你自己再看看
e.g.
...
m = md5.new()
while True:
d = fobj.read(8096)
if not d:
break
m.update(d)
return m.hexdigest()
...
相关问答:
已知Python 中:
s = unicode("测试", "gb2312")
s = u'\u6d4b\u8bd5'
print s
测试
在Delphi里面如何将\u6d4b\u8bd5这样的还原成Gb2312的汉字呢?
找到个方法
......
在list中添加一个类的局部变量 这样做是否合法 请看下面例子:
Python code:
class A():
def __init__( self ):
self.__a = 0
self.__b = 'hello'
def get_a( self ):
ret ......
错误代码如下:
<strong>exceptions.UnicodeEncodeError <br /> &#39;ascii&#39; codec can&#39;t encode characters in position 0-5: ordinal not in range(128)& ......
python 核心编程(第二版) 中 ,11.8.4 闭包有个例子
def counter(start_at=0):
count = [start_at]
def incr():
count[0] += 1
return count[0]
return incr
难道其中count[] ......
#将GB2312格式转为UTF-8格式
f = codecs.open('e:\TestResult.xml', "rb", "gb2312")
text = f.read().encode("utf-8")
  ......