File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-23 10:38:14
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ def convert_to_int (s ,base ):
9
+ try :
10
+ return int (s ,base )
11
+ except Exception , e :
12
+ return 'error'
13
+ print (convert_to_int ('010' ,1 ))
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-23 10:40:58
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ import os
9
+ def invert (x ):
10
+ try :
11
+ return 1 / x
12
+ except ZeroDivisionError :
13
+ return 'error'
14
+ finally :
15
+ print ('invert(%s) done' % x )
16
+ # print(invert(0))
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Date : 2015-05-23 10:31:02
4
+ # @Author : chenhao (wy.chenhao@qq.com)
5
+ # @Link : http://www.xjchenhao.cn
6
+ # @Version : $Id$
7
+
8
+ def convert_to_int (s ,base ):
9
+ try :
10
+ return int (s ,base )
11
+ except ValueError :
12
+ return 'value error'
13
+ except TypeError :
14
+ return 'type error'
15
+ print (convert_to_int (0 ,0 ))
16
+ print (convert_to_int ('010' ,1 ))
17
+ print (convert_to_int ('010' ,8 ))
You can’t perform that action at this time.
0 commit comments