当你的程序中出现异常情况时就需要异常处理。比如当你打开一个不存在的文件时。当你的程序中有一些无效的语句时,Python会提示你有错误存在。
下面是一个拼写错误的例子,print写成了Print。Python是大小写敏感的,因此Python将引发一个错误:
>>> Print 'Hello World'
File "", line 1
Print 'Hello World'
...
分类:
编程语言 时间:
2015-08-13 22:24:59
阅读次数:
221
原文 My old friend, Harrison, had lived in the Mediterranean for many years before he retired to England. He had often dreamed of retiring in England and had planned to settle down in the country. ...
分类:
其他好文 时间:
2015-08-13 14:34:32
阅读次数:
194
Given a complete binary tree, count the number of nodes.
Definition of a complete binary tree from Wikipedia:
In a complete binary tree every level, except possibly the last, is completely fille...
分类:
其他好文 时间:
2015-08-13 01:13:54
阅读次数:
117
Product of Array Except SelfGiven an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the eleme...
分类:
其他好文 时间:
2015-08-12 23:32:49
阅读次数:
201
Single Number I :Given an array of integers, every element appears twice except for one. Find that single one. Note:Your algorithm should have a linea...
分类:
其他好文 时间:
2015-08-12 23:03:53
阅读次数:
141
通过html来比较nginx配置文件和备份的ngixn不同#!/usr/bin/envpythonimportdifflibimportsystry:textfile1=sys.argv[1]textfile2=sys.argv[2]exceptException,e:print"error:"+str(e)print"Usage:diff_nginx.pyfilename1filename2"sys.exit()defreadline(filename):try:fileHan..
分类:
编程语言 时间:
2015-08-12 19:56:30
阅读次数:
195
allow
syntax: allow [ address | CIDR | all ]
default: no
context: http, server, location, limit_except
以上描述的网络地址有权直接访问
deny
syntax: deny [ address | CIDR | all ]
default: no...
分类:
数据库 时间:
2015-08-12 14:38:59
阅读次数:
202
题目Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).For...
分类:
其他好文 时间:
2015-08-12 11:35:51
阅读次数:
89
1.改题目的要求返回一个数组,该数组的product[i]=num[0]*num[1]*.....num[i-1]*num[i+1]*...*num[num.length-1];
2.由于要求出除i位置的元素num[i]的其它所有元素的乘积,假如每次都这么循环遍历一次并作乘法运算,当到num[i]的时候跳过,这样时间复杂度就是O(n*n)
3.另外一种思路就是求出所有的元素的乘积productTotal,然后具体求某个product[i]时,直接product[i]=productTotal/num[i]...
分类:
其他好文 时间:
2015-08-12 10:16:50
阅读次数:
84
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* Yo...
分类:
移动开发 时间:
2015-08-09 12:35:21
阅读次数:
264