The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)
Chris Angelico
rosuav at gmail.com
Sun Mar 20 21:35:39 EDT 2016
On Mon, Mar 21, 2016 at 12:28 PM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
> I got to line 22, saw the bare except, and promptly gave up.
Oh, keep going, Mark. It gets better.
def readstrfile(file):
try:
data=open(file,"r").read()
except:
return 0
return data
def start():
psource=readstrfile(infile)
if psource==0:
print ("Can't open file",infile)
exit(0)
So, if any exception happens during the reading of the file, it gets
squashed, and 0 is returned - which results in a generic message being
printed, and the program terminating, with return value 0. Awesome!
ChrisA
More information about the Python-list
mailing list