I was looking at the documentation and in the example section, I don't see how to create a UUID based on File Contents. Google did not help me either.
I've tried this:
>>> import uuid
>>> data = open('/media/emmc/DCIM/100ABC06/00059.JPG','rb')
>>> contents = data.read()
>>> len(contents)
9155
>>> uuid = uuid.UUID(contents)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/uuid.py", line 134, in __init__
ValueError: badly formed hexadecimal UUID string
Also this:
>>> uuid = uuid.UUID(str(contents))
>>> uuid = uuid.UUID(contents.decode('ascii'))
>>> uuid = uuid.UUID(contents.decode('utf8'))
Please help me understand how to generate a UUID based on File contents in Python 2.7.
If you want to create a hash of a file content, you probably don't need UUID. Instead, you should use hashlib and MD5, SHA-1, SHA-256 or any other supported algorithm to create a fingerprint of your file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With