1

When I try to find the word's count in UTF-8 string I got the next:

UnicodeEncodeError
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

That's what I do

tr.words_count = (str(tr.transcribe).count(' '))

I need to calculate how many words in UTF-8 text and it seems that my method won't work. Do you have any ideas? Thanks

1 Answer 1

4
str(tr.transcribe.decode('utf-8'))

Or better yet,

unicode(tr.transcribe).count(' ')

Or even better (to not get confused if there are multiple spaces in a row),

len(unicode(tr.transcribe).split())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.