Using pathlib's read_bytes method in Python
Python tip:
You can use
read_bytes()
(which handles the opening and closing of the file) frompathlib
'sPath
to read bytes from a file instead of usingwith open()
.Example:
# pathlib import pathlib file_bytes = pathlib.Path("file.pdf").read_bytes() # with open with open("file.pdf", "rb") as file: file_bytes = file.read()