Fill in the blanks to try to open and read from a file.Print an error message in case of an exception. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 2

Fill in the blanks to try to open and read from a file.Print an error message in case of an exception.

try: _____ open("test.txt") as __ : print(f.read()) ____________ print(error)

16th Dec 2017, 1:41 PM
Abrar Saqib
Abrar Saqib  - avatar
22 Answers
+ 16
with open("test.txt") as f : print(f.read()) except : print(error)
4th Jan 2018, 4:46 PM
arun sankar
arun sankar - avatar
+ 4
file =open ("filename.txt", "r") str = file.read() print(len(str)) file.close()
8th Apr 2020, 2:52 AM
Mobin Mirarab
Mobin Mirarab - avatar
+ 3
try: with open("test.txt") as f: print(f.read()) except: print("Error")
26th Oct 2018, 3:42 PM
Houcem Eddine Aouissaoui
Houcem Eddine Aouissaoui - avatar
+ 2
try: with open("test.txt") as f : print(f.read()) except: print("Error")
3rd Aug 2019, 5:37 AM
GYANENDRA PAL SINGH
GYANENDRA PAL SINGH - avatar
+ 2
https://youtu.be/Tg4Du8eUFw8 this is youtub channel link in which full tutorial video
8th Jul 2020, 11:07 AM
Code TO Programming
+ 2
1. with 2. f 3. except: is true answer
2nd Mar 2021, 3:47 PM
v manojbabu
v manojbabu - avatar
+ 1
with/f/except
3rd Jan 2018, 1:06 PM
Ponnuraj Nadar
Ponnuraj Nadar - avatar
+ 1
with open("test.txt") as f : print(f.read()) except : print(error) follow on insta = gyan.22
3rd Aug 2019, 5:41 AM
GYANENDRA PAL SINGH
GYANENDRA PAL SINGH - avatar
+ 1
Fill in the blanks to create a valid with statement, reading the contents of the file. with open("test.txt") as f: print(f. read ())
8th Sep 2019, 10:43 PM
OUSSAMA ROMDHANI
OUSSAMA ROMDHANI - avatar
+ 1
27th Jan 2020, 1:28 PM
Chrad
Chrad - avatar
0
Actually READ the tutorial before that section of the python quiz.
17th Dec 2017, 6:51 AM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar
0
the three answers are: 'with', 'as', and 'read'
23rd Jul 2020, 6:25 PM
Michael Yip
Michael Yip - avatar
0
the answers are: 'with', 'as', and 'except:'
23rd Jul 2020, 6:28 PM
Michael Yip
Michael Yip - avatar
0
7
13th Dec 2020, 9:48 AM
8-B-_ Y DENNITH UZWAL
8-B-_ Y DENNITH UZWAL - avatar
0
try: with open("test.txt") as f : print(f.read()) except: print("Error")
15th Jan 2021, 5:44 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
0
1. open 2. readlines 3. 1
16th Aug 2021, 11:12 AM
Sahana ca
Sahana ca - avatar
0
with open('admin panel.txt','a') as s: plzz tell corrct line plzz
20th Sep 2021, 9:49 AM
ammy8588
0
FILE* fptr = fopen("test", "r"); if (feof(fptr)) { printf("End of file reached"). exit (42); }
20th Oct 2021, 9:11 AM
Shilpa L
0
If the file test.txt has 7 lines of content, what will the following expression return? len(open("test.txt").readlines())
7th May 2022, 9:30 AM
yehia Abdoul-aziz
0
HEY guys hows your learning going on
12th Jul 2022, 4:16 AM
Shivam
Shivam - avatar