All Courses

What is file hashing in python?

By Neha, 2 years ago
  • Bookmark
0

What is file hashing and it is use?

Hashing
Python
1 Answer
0

A hash is a function that converts a variable length sequence of bytes to a fixed length sequence.

Hashing files can be advantageous for many reasons. Hashes can be used to check if two files are identical or verify that the contents of a file haven't been corrupted or changed.


You can use hashlib to generate a hash for a file:


import hashlib

hasher = hashlib.new('sha256')
with open('myfile', 'r') as f:
      contents = f.read()
      hasher.update(contents)

print hasher.hexdigest()

Your Answer

Webinars

Why You Should Learn Data Science in 2023?

Jun 8th (7:00 PM) 289 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More