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:

Related questions

0 votes
1 answer
asked Mar 23, 2021 in Python by Rekha (2.2k points)
0 votes
3 answers
0 votes
1 answer
0 votes
2 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...