LK CS BookHomeHomePythonPythonFrontendFrontendShellShell
GitHubGitHub (opens in a new tab)
      • Horizontal Scroll
      • Reactangle Radius Clip
    • Auto Wrap in Treewiget Cell
  • Get File Hash
  • Get File Size
  • Get Func Source
  • Load Module by Path
  • Pip Commonly Used
  • Poetry Memo
  • Streamlit
  • Text Parens Scanner
  • Watch File Changes
  • Xlsxwriter
  • Zipfiles
  • Home
        • Horizontal Scroll
        • Reactangle Radius Clip
      • Auto Wrap in Treewiget Cell
    • Get File Hash
    • Get File Size
    • Get Func Source
    • Load Module by Path
    • Pip Commonly Used
    • Poetry Memo
    • Streamlit
    • Text Parens Scanner
    • Watch File Changes
    • Xlsxwriter
    • Zipfiles
    • Mdx Embed Video
    • Mdx Syntax Highlighting for Pycharm
    • Bore Frp
    • Chrome App Mode
    • Ssh Keygen
      • Create Relative Path Lnk File
Question? Give us feedback → (opens in a new tab)Edit this page
Python
Get File Hash

Hash File Content

import hashlib
import os
 
def get_file_hash(path: str) -> str:
    """
    if file is too large, read the first 8192 bytes
    """
    with open(path, 'rb') as file:
        md5 = hashlib.md5()
        if os.path.getsize(path) > 8192:
            md5.update(file.read(8192))
        else:
            md5.update(file.read())
    return md5.hexdigest()
Auto Wrap in Treewiget CellGet File Size

Made by Likiata, powered by Nextra