python的异常Exception
Python 的异常处理机制
Python代码
try:
raise Exception("a", "b")
except Exception,e:
print e
finally:
print "final"
('a', 'b')('a', 'b')
final
同样可以处理多个异常筛选。
Python代码
try:
raise EOFError("aa", "bb")
except RuntimeError, e:
print "[RuntimeErro]: ", e
except EOFError, e:
print "[EOFError]: ", e
except Exception, e:
print "[Error]: ", e
finally:
print "final"
[EOFError]: ('aa', 'bb')
final
除了异常参数,我们还可以用sys的一些方法来获取异常信息。
Python代码
import sys
try:
raise RuntimeError("the runtime error raised")
except:
print sys.exc_info()
(<type 'exceptions.RuntimeError'>, RuntimeError('the runtime error raised',), <traceback object at 0x00DC5CB0>)
缺省情况下,异常类都继承自 Exception。
Python代码
>>>>>> class MyException(Exception):
pass
>>>>>> try:
raise MyException("My Exception raised!")
except:
print sys.exc_info()
(<class '__main__.MyException'>, MyException('My Exception raised!',), <traceback object at 0x00DC58F0>)
>>>>>>
相关文档:
def getText(self,nodelist):
rc=""
for node in nodelist:
if node.nodeType == node.TEXT_NODE or node.nodeType == node.CDATA_SECTION_NODE:
rc = rc + node.data
return rc
def parseXML(self,requesturl,xml):
dom = minidom.parse(requesturl)
for node in dom.getElementsByTagName('ca ......
urllib模块提供的上层接口,使我们可以像读取本地文件一样读取www和ftp上的数据。每当使用这个模块的时候,老是会想起公司产品的客户端,同事用C++下载Web上的图片,那种“痛苦”的表情。我以前翻译过libcurl教程,这是在C/C++环境下比较方便实用的网络操作库,相比起libcurl,Python的url ......
转自:
http://hi.baidu.com/feng2211/blog/item/8b86b6d9816a3f2710df9b79.html
和
http://i.19830102.com/archives/164
Python 版本:2.6
下载地址:http://www.python.org/download/releases/2.6.1/
下载msi文件并安装
MySQLdb版本: MySQL-python-1.2.2.win32-py2.6.exe
下载地址:http://home.netimperia.com/ ......
conn = httplib.HTTPConnection(EPG_IP + ":" + HTTP_PORT)
url = FAV_URL_PARTH +"userid=" + USER_ID + FAV_DIR_MODIFY
param = '''<ps100request id="Favorite.Category.modify">
<categoryid>'''+categoryid+'''</categoryid>
<categoryname>'''+categoryname+'''</ ......
转帖:
http://blog.csdn.net/wyingquan/archive/2008/12/20/3561094.aspx
用python自带的binascii模块计算字符串的校验码,出来的是负值,与用c写的程序得出的校验码不一样,所以就研究了一下。发现别人用的python3.0版本binascii模块计算出的crc32校验码是我想要的,没办法只好自己用python实现一下crc32的算法了。发 ......