10-6
def safe_open(filename=raw_input('your file name: ')):
try:
f = open(filename)
return f
except IOError as e:
print e
return None
10-8
def safe_input():
try:
myinput = raw_input(">: ")
except (EOFError, KeyboardInterrupt):
myinput = None
return myinput
10-9
def safe_sqrt2(num):
import math
import cmath
try:
return math.sqrt(num)
except (NameError, ValueError):
return cmath.sqrt(num)