python 代码片段17
#coding=utf-8
try:
get_mutex()
do_some_stuff()
except (IndexError,KeyError,AttributeError),e:
log("ERROR:data retrieval accessing a non-existent element")
finally:
free_mutex()
# 用raise抛出异常
'''
加入你在自己的库里创建了一个api调用要求传入一个大于0的正整数。在内置
函数isinstance的帮助下(检查对象类型),你代码看起来应该是这样的:
'''
def foo(must_be_positive_int):
''' foo() --take positive integer and process it '''
#check if integer
if not isinstace(must_be_positive_int):
raise TypeError("ERROR foo():must pass in an integer")
#check if positive
if must_be_positive_int<1:
raise ValueError("ERROR foo():integer must be greater than zerio!")
#normal processing here
python 代码片段17的更多相关文章
- Python 代码片段收藏
list 列表相关 list 中最小值.最大值 import operator values = [1, 2, 3, 4, 5] min_index, min_value = min(enumerat ...
- 有用的Python代码片段
我列出的这些有用的Python代码片段,为我节省了大量的时间,并且我希望他们也能为你节省一些时间.大多数的这些片段出自寻找解决方案,查找博客和StackOverflow解决类似问题的答案.下面所有的代 ...
- 2019-01-29 VS Code创建自定义Python代码片段
续前文[日常]Beyond的歌里最多是"唏嘘"吗? - Python分词+词频最后的想法, 发现VS Code支持用户自定义代码片段: Creating your own snip ...
- Python - 代码片段,Snippets,Gist
说明 代码片段来自网上搬运的或者自己写的 华氏温度转摄氏温度 f = float(input('请输入华氏温度: ')) c = (f - 32) / 1.8 print('%.1f华氏度 = %.1 ...
- 32个使用python代码片段
1.冒泡排序 lis = [56,12,1,8,354,10,100,34,56,7,23,456,234,-58] def sortport(): for i in range(len(lis ...
- python 代码片段26
#coding=utf-8 ''' 使用空格而不是tab 因为无论在什么平台上开发,你的代码总是有可能会被移动或是复制到 另一不同架构的机器上,win32是4个空格,unix是8个空格,干脆 还是使用 ...
- python 代码片段25
#coding=utf-8 # 虽然python是面向对象的语言,但是没有显式的构造函数概念. # python没有new关键词 class MyClass(object): pass m=MyCla ...
- python 代码片段23
#coding=utf-8 #python还支持动态的实力属性,即那些没有在类定义里生命的属性, #可以"凭空"创造出来 john.tatto='Mom' #继承 class Em ...
- python 代码片段22
#coding=utf-8 class AddressBookEntry(object): version=0.1 def __init__(self, name,phone): self.name ...
随机推荐
- c语言运算符
一.op=形式的赋值操作符 int a=0; a+=1; //等价于 a=a+1;// a*=1; 二.op=类表达式 int a=10,b=5; a/=b;//等价于a=a/b; a*=b+1; ...
- DB2 嵌入式应用中定义游标(开放平台上)
DECLARE CURSOR statement The DECLARE CURSOR statement defines a cursor. Invocation Although an inter ...
- Loadrunner之API测试
//API函数 web_submit_data web_custom_request //支持https请求 web_set_sockets_option("SSL_VERSION&qu ...
- Jquery.Datatables 基本创建方法
基本创建 <!--定义操作列按钮模板--> <script id="tpl" type="text/x-handlebars-template" ...
- App 开发:Hybrid 架构下的 HTML5 应用加速方案
在移动 App 开发领域,主流的开发模式可分为 Native.Hybrid.WebApp 三种方式.然而 2013 年,纯 WebApp 开发模式的发展受到一定挫折,以 Facebook 为代表的独立 ...
- ListView 完全优化 + 多种listitem布局处理
# 百度了下,感觉下面的博客文章还都挺全面的,写的很好,直接分享得了 Android性能优化--Listview优化 - tonycheng93 - 博客园http://www.cnblogs.co ...
- 【转载】 Python 调整屏幕分辨率
转载来自: http://www.cnblogs.com/fatterbetter/p/4115423.html 需要用windows的api,ChangeDisplaySettings 实现代码如下 ...
- 蓝桥杯 算法训练 Torry的困惑(基本型)(水题,筛法求素数)
算法训练 Torry的困惑(基本型) 时间限制:1.0s 内存限制:512.0MB 问题描述 Torry从小喜爱数学.一天,老师告诉他,像2.3.5.7……这样的数叫做质数.Torry突 ...
- soapUI 使用Property
DRY 原则是一个比较普适的东西,在使用soapUI测试的时候,为了make life easy,我们必须要使用Property来集中化一些设置. 比如说从dev->test->uat 的 ...
- phpcms-v9系统搭建wap网站及单页面
如需要绑定域名为wap.domain.com,作下如操作: 一.把wap.domain.com域名绑定到你的这个网站主机上. 二.在网站后台——模块——手机门户域名里面填写“http://wap.do ...