Sunday, 3 March 2019

Find the Hash of File in Python

# Python rogram to find the SHA-1 message digest of a file
# import hashlib module
import hashlib
def hash_file(filename):
""""This function returns the SHA-1 hash
of the file passed into it"""
# make a hash objectv h = hashlib.sha1()
# open file for reading in binary mode
with open(filename,'rb') as file:
# loop till the end of the file
chunk = 0
while chunk != b'':
# read only 1024 bytes at a time
chunk =
# return the hex representation of digest return h.hexdigest()
message = hash_file("track1.mp3") print(message)



  1. We as a team of real-time industrial experience with a lot of knowledge in developing applications in python programming , aws training , ccna training (7+ years) will ensure that we will deliver our best in python training in chennai. , and we believe that no one matches us in this context.

    ccna training in chennai
    aws training in chennai
    aws devops training in chennai
    python training
    python training in chennai


Popular Posts


Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (94) R (69) Selenium Webdriver (2) Software (13) SQL (27)