Python 3 : Typeerror: Type Str Doesn't Support The Buffer Api
I'm getting the error : TypeError: Type str doesn't support the buffer API when trying to run the following code : import random import string WORDLIST_FILENAME = 'words.t
Solution 1:
You loaded your words as binary data, by using the 'rb'
mode when opening the file:
inFile = open(WORDLIST_FILENAME, 'rb', 0)
then tried to see if a string is contained in that binary data:
if(guess in secretWord ) :
If WORDLIST_FILENAME
is text, don't use binary mode to read it. Use a text mode:
inFile = open(WORDLIST_FILENAME, 'r', encoding='ascii')
The file you linked is a simple ASCII-encoded file, so I used that codec to decode it to a Unicode string.
Post a Comment for "Python 3 : Typeerror: Type Str Doesn't Support The Buffer Api"