Now I am rewriting Python2 scripts to Python3 scripts. In the Python2 script, the code below was successfully launched. But in the Python3 script, it had an syntax error. If somebody knows why it happens, please tell me why and how can I fix it.
hash = []
for root, dirs, files in os.walk(directory):
for names in files:
if not names.endswith( '.py' ):
continue
filepath = os.path.join(root,names)
try:
f1 = open(filepath, 'rb')
except:
# You can't open the file for some reason
f1.close()
continue
hash.append( (names, hashlib.sha256(f1.read()).hexdigest() ) )
hash.sort( key=lambda tup: tup[ 1 ])
digest = reduce( lambda d, (x,y): d + '\n' + y, hash, '')