When creating large simulations, you may sometimes create unique identifiers for each of it. This is useful to cache intermediate results for instance. This is the main function of hashes. We will here create a simple one-liner function to generate one.

In [1]:
filename = 'https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107001.jpg'
print ('filename=', filename)
filename= https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107001.jpg
In [2]:
import os
import hashlib
hash_str = hashlib.sha224(filename.encode('utf-8')).hexdigest()
print('hash_str=', hash_str)
hash_str= d9dee4e30946f8306a87b83b3a5723e9b9546e114e9f477025090ba2
In [3]:
filename = 'https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107002.jpg'
print ('filename=', filename)
print('hash_str=', hashlib.sha224(filename.encode('utf-8')).hexdigest())
filename= https://raw.githubusercontent.com/bicv/SLIP/master/database/serre07_targets/B_N107002.jpg
hash_str= fd94b7e0e5e950996d548c0777ccf7f800205065d9c28c1f255a3e82
In [4]:
%load_ext watermark
%watermark
2018-06-13T13:09:44+02:00

CPython 3.6.5
IPython 6.4.0

compiler   : GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)
system     : Darwin
release    : 17.5.0
machine    : x86_64
processor  : i386
CPU cores  : 4
interpreter: 64bit
In [5]:
%load_ext version_information
%version_information numpy, hashlib
Out[5]:
Software Version
Python 3.6.5 64bit [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
IPython 6.4.0
OS Darwin 17.5.0 x86_64 i386 64bit
numpy 1.14.4
hashlib The 'hashlib' distribution was not found and is required by the application
Wed Jun 13 13:09:46 2018 CEST