将对象保存到文件中
>>> import pickle
>>> pickle.dump(a,f)>>>
打开xx1,查看内容
c__builtin__
set
p0
((lp1
I1
aI2
aI3
atp2
Rp3
.
异常处理中使用参数
>>> def raise_f2():
raise Exception('myerr')
>>> try:
raise_f2()
except Exception as dd:
print dd
myerr
>>> try:
raise_f2()
except Exception as dd:
print dd.args
('myerr',)
异常中使用类
>>> class Myerror(Exception):
def __init__(self,value):
self.value=value
def __str__(self):
return repr(self.value)
>>> try:
raise Myerror(66*9)
except Myerror as ee:
print ee
print ee.value
594
594
三元操作符
>>> a=3 if 3>6 else 9
>>> a
9
>>>