Python error "TypeError: 'encoding' is an invalid keyword argument for this function"
I have a tine code snippet and it gives me the following error:
TypeError: 'encoding' is an invalid keyword argument for this function
code:
import numpy as np
trump = open('speeches.txt', encoding='utf8').read()
# display the data
print(trump)
You are getting typeerror: 'encoding' is an invalid keyword argument for this function error because you are using an argument named encoding in the open method and the open method does not have a parameter named encoding.
To resolve this type of error you have to do is use the io module. like this:
import io
trump = io.open('speeches.txt', encoding='utf8').read()