Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (19.9k points)

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)

1 Answer

0 votes
by (25.1k points)

You are getting this 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 issue all you have to do is use the io module. like this:

import io

trump = io.open('speeches.txt', encoding='utf8').read()

You can learn more about file handling in python using this python tutorial:

Browse Categories

...