wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在为Windows操作系统中的大文件计算SHA-1哈希时,Python崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我想知道我是否可以对这个 python脚本有一些新的眼光.它适用于中小型文件,但是大型文件(4-8GB左右)在运行几分钟会出现无法解决的崩溃. Zipped script here 要么: import sys import msvcrt import hashlib #Print the file name (and its LOCATIOn) to be hashed print 'F
我想知道我是否可以对这个 python脚本有一些新的眼光.它适用于中小型文件,但是大型文件(4-8GB左右)在运行几分钟会出现无法解决的崩溃.

Zipped script here

要么:

import sys
import msvcrt
import hashlib

#Print the file name (and its LOCATIOn) to be hashed  
print 'File:  ' + str(sys.argv[1])

#Set "SHA1Hash" equal to SHA-1 hash
SHA1Hash = hashlib.sha1()

#Open file specified by "sys.argv[1]" in read only (r) and binary (b) mode
File = open(sys.argv[1],'rb')

#Get the SHA-1 hash for the contents of the specified file
SHA1Hash.update(File.read())

#Close the file
File.close()

#Set "SHA1HashBase16" equal to the hexa@R_450_6221@l of "SHA1Hash"
SHA1HashBase16 = SHA1Hash.hexdigest()

#Print the SHA-1 (hexa@R_450_6221@l) hash of the file
print 'SHA-1: ' + SHA1HashBase16

#Make a blank line
print ' '

#Print "Press any key to conTinue..."
print 'Press any key to conTinue...'

#"Press any key to conTinue..." delay
char=0
while not char:
    char=msvcrt.getch()

* 更新 *

使用python脚本计算大文件的SHA-1哈希值.感谢Ignacio Vazquez-Abrams指出错误和Tom Zych的代码.

Zipped source here

使用简单地拖放要在脚本顶部进行哈希处理的文件.或者,您可以使用命令提示符,使用:

SHA-1HashGen.py Path&File

SHA-1HashGen.py是脚本的文件名,Path& File是要散列的文件的路径和文件名.

或者将脚本放入SendTo文件夹(在Windows操作系统中; sHell:sendto)以将其作为右键单击选项.

停止一次阅读文件;你正在消耗系统上的所有内存.请改为读入16MB左右的块.
data = File.read(16 * 1024 * 1024)

大佬总结

以上是大佬教程为你收集整理的在为Windows操作系统中的大文件计算SHA-1哈希时,Python崩溃全部内容,希望文章能够帮你解决在为Windows操作系统中的大文件计算SHA-1哈希时,Python崩溃所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。