I am trying to use the fileinput.input() module to read in the lines from a bunch of files in a directory and occasionally receive an IOerror exception. What is the best way to handle this exception so that if 1 of the items in the list i'm feeding fileinput,input() generates this IOError, i can get fileinput to simply continue onto the next item in the list ?
Skrell
0
Light Poster
Recommended Answers
Jump to PostWhen you get IOError,pass make it countinue to end.
Other errors than IOError will raise error as normal.try: doSomething() except IOError: pass
Jump to PostYou must put try around the fileinput that is in try to line "5.5" and indent the print line and 7 to same level as try: (current print indention).
Jump to PostActually I did not realize you are using fileinput as iterator already in for line. To get hat to work I think you must wrap it in function passing IOErrors.
string.count is not also good style, you should use the method of string itself: "abcd".count("a")
All 10 Replies
snippsat
661
Master Poster
Skrell
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Skrell
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Skrell
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Skrell
0
Light Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.