python 中exception,class学习
2014-11-07 18:34
309 查看
python 中exception,class 学习
instroduction:
Object2 = Object1 ( like java)
if Object1 is class object , then copy by reference;
if Object1 is basic type, then copy by value
1. exception
主要结构:
try:
exception ValueError:
exception ZeroDivisionError:
exception NameError:
exception TypeError:
exception:
finally:
2. custom exception
class Error(Exception):
pass
def MyError(Error):
def __init__(self,value):
print value
self.value = value
def __str__(self):
return repr(self.value)
3. class
class Bird:
number = 0
def __init__(self,name):
self.name = name
print 'Initializing %s' % self.name
def __del__(self):
print 'del',self.number
def fly(self):
print 'fly %d' % self.number
def add(self):
self.number = self.number + 1
def sub(self):
self.number = self.number - 1
class Sparrow(Bird):
def __init__(self,name,alias):
Bird.__init__(self,name)
self.alias = alias
print 'alias is %s ' % self.alias
def fly(self):
print 'Sparrow fly %s' % self.alias
description:
constructor: __init__
destructor:__del__
static data: number
4. file input/output
cPickle or pickle: store the object consistently
instroduction:
Object2 = Object1 ( like java)
if Object1 is class object , then copy by reference;
if Object1 is basic type, then copy by value
1. exception
主要结构:
try:
exception ValueError:
exception ZeroDivisionError:
exception NameError:
exception TypeError:
exception:
finally:
2. custom exception
class Error(Exception):
pass
def MyError(Error):
def __init__(self,value):
print value
self.value = value
def __str__(self):
return repr(self.value)
3. class
class Bird:
number = 0
def __init__(self,name):
self.name = name
print 'Initializing %s' % self.name
def __del__(self):
print 'del',self.number
def fly(self):
print 'fly %d' % self.number
def add(self):
self.number = self.number + 1
def sub(self):
self.number = self.number - 1
class Sparrow(Bird):
def __init__(self,name,alias):
Bird.__init__(self,name)
self.alias = alias
print 'alias is %s ' % self.alias
def fly(self):
print 'Sparrow fly %s' % self.alias
description:
constructor: __init__
destructor:__del__
static data: number
4. file input/output
cPickle or pickle: store the object consistently
相关文章推荐
- Debian Linux下的Python学习——class
- 「学习笔记——Python」Google's Python Class 学习笔记
- Google Python Class 学习笔记(2) 正则表达式
- python学习笔记1-元类__metaclass__
- 通过代码学习python之@property,@staticmethod,@classmethod
- 《笨办法学 Python》 学习笔记05 —— Class
- Python 学习笔记:class
- Python classmethod staticmethod 进价学习
- 十五、python class 类学习笔记
- python学习笔记1---class
- 深入学习Django源码基础1 - 深刻理解Python中的元类(metaclass)
- 学习Python:深刻理解Python中的元类(metaclass)
- python学习笔记 class
- Google Python Class 学习笔记(1) Introduce String list del
- python学习之self,cls,staticmethod,classmethod
- Python3与Python2中print的用法改变与Class获取属性学习
- Python学习笔记(8)class, for loop, while loop, spaceship project
- python 学习笔记——set() class 集合类型
- Python 学习笔记 - 10.类(Class) 1
- python学习之路八--类(class)