• Register
1 vote
527 views

Problem:

I was trying open some file using python and I wrote the code:

import numpy as np

doland = open('talks.txt', encoding='utf8').read()

holland = open('h-talks.txt', encoding='utf8').read()


print(doland)

 

But the code always hrows a error message which is:

Traceback (most recent call last):
  File "txt.py", line 3, in <module>
    doland = open('talks.txt', encoding='utf8').read()
FileNotFoundError: [Errno 2] No such file or directory: 'talks.txt'

^
TypeError: 'encoding' is an invalid keyword argument for this function

Whats problem in my code please help me to solve this.

Thanks in advance.

8 6 2
4,980 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

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. 

And please make sure there is a file called ‘talks.txt’

If you want your code to work use:

import io

doland = io.open('talks.txt', encoding='utf8').read()

holland = io.open('h-talks.txt', encoding='utf8').read()

So your code should be like:

import numpy as np
import io

doland = io.open('talks.txt', encoding='utf8').read()

holland = io.open('h-talks.txt', encoding='utf8').read()


print(doland)
print(holland)

 

Now it shall work fine. If you dont understand aks me anything you want to know.

Happy coding.

11 6 4
34,950 points

Related questions

0 votes
1 answer 59 views
59 views
Problem: I wrote the following code which extracts the info. of a file and orders it alphabetically based on its second column objects: import csv import operator import sys def re_sort(in_file='books.csv', out_file='books_sort.csv'): data = csv.reader(open('books. ... function. Do you guys see reasons why this may be happening. The following if a structured version of the contents in the file
asked Feb 21 Mashhoodch 13k points
0 votes
1 answer 74 views
74 views
Problem: How to fix this error: typeerror: string argument without an encoding HELP! I need help understanding this error: typeerror: string argument without an encoding Can someone please help fix this, I am new in python().
asked Mar 1 Mashhoodch 13k points
0 votes
1 answer 27 views
27 views
Solution: How to I Solve this: typeerror: data argument can't be an iterator HELP! I need help understanding this: typeerror: data argument can't be an iterator Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 3 Mashhoodch 13k points
0 votes
1 answer 56 views
56 views
def choose_option(self): if self.option_picker.currentRow() == 0: description = open(":/description_files/program_description.txt","r") self.information_shower.setText(description.read()) elif self.option_picker.currentRow() == 1: requirements = open(":/description_files/ ... it as argument in open function, but when i am using it for loading of pictures and icons everything is fine.
asked Oct 24, 2020 psandprop 2.4k points
0 votes
1 answer 2 views
2 views
Problem: For the above query, I used Google to try to find an answer on the internet. However, I have no helpful suggestions that I can ask someone to respond to my query.
asked 6 days ago zayed1 35.6k points
0 votes
1 answer 8 views
8 views
Problem: How to I Solve this: argument of type 'nonetype' is not iterable HELP! I need help understanding this: argument of type 'nonetype' is not iterable Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 5 Mashhoodch 13k points
0 votes
1 answer 168 views
168 views
Problem: Input() function in python is used to get a input value from the command prompt, when the program executes the input() function will display a message(says wat the input is for). it just takes one argument.
asked Feb 17 Mashhoodch 13k points
0 votes
1 answer 2 views
2 views
Problem: Please help me &hellip; how can I solve it? typeerror: must use keyword argument for key function
asked 1 day ago Ifra 25.7k points
0 votes
1 answer 5 views
5 views
Problem: As i posted one more question related to this, and now i have one more problem, can anyone help me out?
asked Apr 4 niyatiry 3.6k points