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, 2019 in Python by Waseem
• 4,540 points
682 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, 2019 by Mohammad
• 3,230 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, 2019 in Python by Bob
14,821 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 5, 2019 in Python by Shabnam
• 930 points
2,065 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
• 58,020 points
23,154 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
• 58,020 points
831 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,466 views
0 votes
1 answer
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, 2019 in Python by Mohammad
• 3,230 points
725 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, 2019 in Python by Mohammad
• 3,230 points
909 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