• Register
1 vote


Hello Pal,

I have a query regarding the python programming language. The question is, which method will return an empty string when it has attempted to read beyond the end of a file?
Do you have any idea about this?

12 7 7
15,250 points

1 Answer

0 votes


I understand that you wanted to read a file as input by your program. If I am not wrong you asked the question, which method will return an empty string when it reached the end of the file.

When a program reaches the (EOL) end of the line the .read() method returns an empty string whether the input file has a string or not.

f = open('test_file.txt')

>>> f.read() # reading the entire file
'Test File has data.'

>>> f.read() # Here you've reached the end of the file 

f.read() function return (‘ ‘). Here the program reached the end of the file.

I hope this will help you. To understand the .read() function better, follow the LINK

13 9 6
94,240 points

Related questions

1 vote
1 answer 184 views
Problem: Hello all, I am a new, college student who is learning python programming. I am thinking to write a program that will input a text file and read all the vowels from it and determines when it comes to the end of the file. So, is it possible to create a while loop that determines when the end of a file has been reached? Thanks in advance.
asked Mar 16 Gavin 15.3k points
1 vote
1 answer 42 views
Problem: I wrote a program that asks the user to enter the amount of a purchase and then it sums up the total bill with 15% vat and 0.07% service tax. I wrote the program in python: vat = 0.15 sales_tax = 0.075 product_price = float(input("Please enter the ... not defined I can not solve this thing. I am new in python programming language so please help me to solve this error. Thanks in advance.
asked May 6 samhaz 5k points
0 votes
1 answer 35 views
Problem: Which of the following will open a file named MyFile.txt and allow you to read data from it? a. File file = new File("MyFile.txt"); b. Scanner inputFile = new Scanner("MyFile.txt"); c. File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); d. PrintWriter inputFile = new PrintWriter("MyFile.txt"); Does any one know correct file name?
asked Feb 22 maddi86 5.4k points
0 votes
1 answer 68 views
Solutions: I am new in programming and my logic is not good, can anyone give the right solution? Write an expression that evaluates to true if and only if the C-string s equals the C-string "end"?
asked Feb 14 maddi86 5.4k points
1 vote
1 answer 38 views
Problem: Hello people I am doing python programming for a few days. I am still learning. Could anybody please help me by showing how can I import a text file and read five lines from it by my python program? If possible make it as easy words as possible for me. Thanks.
asked Mar 11 Gavin 15.3k points