Python AttributeError: tuple object has no attribute encode in hashlib.encode

Python AttributeError: tuple object has no attribute encode in hashlib.encode

You are chaining heterogeneous types together, which is a certain cause of headaches.

Presumably ALC is a string, so chain first yields all the characters from the string. When it moves on to product(ALC, repeat=2), it starts yielding tuples, since thats how product works.

Just yield homogeneous types from your chain call (i.e. always yield tuples, joining them when you need a string) and the headaches disappear.

for chars in chain(*[product(ALC, repeat=n) for n in range(1,4)]):
    ...
    a.update(.join(chars).encode(utf-8))

Your error is trying to convert this tuple to utf-8. Try remove this line a.update(chars.encode(utf-8)

When the interpreter shows tuple object has no attribute encode means that the object tuple does not support convert that way.

But, if you would like to convert all these things, use #coding: utf-8 in the first line of your program.

Python AttributeError: tuple object has no attribute encode in hashlib.encode

Leave a Reply

Your email address will not be published. Required fields are marked *