how to check for exceptions in a file?

0 votes
what are the different approaches to check the exceptions in a file and avoid it in python?
Mar 20 in Python by Waseem
• 4,470 points
19 views

1 answer to this question.

0 votes
try
{
 if (!file.exists("TextFile1.txt"))
    throw new FileNotFoundException();
}
catch(FileNotFoundException e)
{
   // your message here.
}
answered Mar 20 by Mohammad
• 3,060 points

Related Questions In Python

0 votes
2 answers

How to check if a csv file is empty in pandas?

Try this: df = pd.DataFrame(columns=['Name', 'ID', 'Department']) if df.empty ...READ MORE

answered Jul 1 in Python by Bob
544 views
+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 4 in Python by Shabnam
• 920 points
50 views
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 56,900 points
4,104 views
0 votes
1 answer

In python how to test a string for a substring

if "ABCD" in "xxxxABCDyyyy": This can be used ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 56,900 points
90 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 328 views
0 votes
1 answer

how do i check for exceptions in python?

use self.assertRaises method as a context manager. def ...READ MORE

answered Mar 12 in Python by Mohammad
• 3,060 points
49 views
0 votes
1 answer

how to delete a file in python?

to delete a file import os os.remove('filename') this will delete ...READ MORE

answered Mar 18 in Python by Mohammad
• 3,060 points
22 views