python2.x有好几个地方不人性化,Exception是其中一个,刚开始是学py3的,后来好多开源lib都是2.x的,所以推荐初学者或者使用者使用2.x的
try扑捉多个exception时需要加括号,如果不加括号则视为exception的信息
#!/usr/bin/python
def KelvinToFahrenheit(Temperature):
temp = 0
try:
assert (Temperature >= 0),"Colder than absolute zero!"
temp = ((Temperature-273)*1.8)+32/0
except (AssertionError,ZeroDivisionError),arg:
print "some problem...",arg
else:
print "All is ok..."
return temp
print KelvinToFahrenheit(273)
print int(KelvinToFahrenheit(505.78))
print KelvinToFahrenheit(-5)