Python error TypeError encoding is an invalid keyword argument for this function

0 votes

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)
Aug 2, 2019 in Python by Harshit
14,669 views

1 answer to this question.

0 votes

Trying using the io module for this purpose. 

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


This should work.

To know more, It's recommended to join our Python Training in Chennai today.

answered Aug 2, 2019 by Vaishali

edited Oct 7, 2021 by Sarfaraz

Related Questions In Python

0 votes
0 answers

Help, How can I fix this? TypeError: Getting error as __init__() got an unexpected keyword argument 'rotaion_range'.

datagen = ImageDataGenerator(zoom_range=0.2,rotaion_range=10,width_shift_range=0.1, height_shift_range=0.1,horizontal_flip=True, vertical_flip = False ...READ MORE

Oct 20, 2021 in Python by anonymous
• 120 points
576 views
+2 votes
10 answers

How to fix this? ValueError: invalid literal for int() with base 10 error in Python

The following are totally acceptable in python: passing ...READ MORE

answered Nov 16, 2018 in Python by Nymeria
• 3,560 points
409,221 views
+1 vote
1 answer

What is the function for Factorial in Python

Easiest way: math.factorial(x) (available in 2.6 and ...READ MORE

answered Aug 21, 2018 in Python by Priyaj
• 58,020 points

edited Aug 21, 2018 by Omkar 1,348 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
0 votes
3 answers

What is the python keyword “with” used for?

The with statement in Python simplifies exception ...READ MORE

answered Jul 19, 2019 in Python by rahul
• 360 points
1,650 views
0 votes
1 answer

Python error "TypeError: range() integer end argument expected, got numpy.float64."

Hi @Kashish, try something like this: for i ...READ MORE

answered May 27, 2019 in Python by Harish
2,973 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP