Python异常处理体系简介
Python内建异常体系结构
BaseException
+-- SystemExit
+-- KeyboardInterrupt
+-- GeneratorExit
+-- Exception
+-- StopIteration
+-- StandardError
| +-- BufferError
| +-- ArithmeticError
| | +-- FloatingPointError
| | +-- OverflowError
| | +-- ZeroDivisionError
| +-- AssertionError
| +-- AttributeError
| +-- EnvironmentError
| | +-- IOError
| | +-- OSError
| | +-- WindowsError (Windows)
| | +-- VMSError (VMS)
| +-- EOFError
| +-- ImportError
| +-- LookupError
| | +-- IndexError
| | +-- KeyError
| +-- MemoryError
| +-- NameError
| | +-- UnboundLocalError
| +-- ReferenceError
| +-- RuntimeError
| | +-- NotImplementedError
| +-- SyntaxError
| | +-- IndentationError
| | +-- TabError
| +-- SystemError
| +-- TypeError
| +-- ValueError
| +-- UnicodeError
| +-- UnicodeDecodeError
| +-- UnicodeEncodeError
| +-- UnicodeTranslateError
+-- Warning
+-- DeprecationWarning
+-- PendingDeprecationWarning
+-- RuntimeWarning
+-- SyntaxWarning
+-- UserWarning
+-- FutureWarning
+-- ImportWarning
+-- UnicodeWarning
+-- BytesWarning
捕获异常的方式
方法一:捕获所有的异常
''' 捕获异常的第一种方式,捕获所有的异常 '''
try:
a = b
b = c
except Exception,data:
print Exception,":",data
'''输出:<type 'exceptions.Exception'> : local variable 'b'
referenced before assignment ''
方法二:采用traceback模块查看异常,需要导入traceback模块
''' 捕获异常的第二种方式,使用traceback查看异常 '''
try:
a = b
b = c
except:
print traceback.print_exc()
'''输出
相关文档:
1)Excel hyperlink:
xlsApp = win32com.client.Dispatch('Excel.Application')
cell = xls.App.ActiveSheet.Cells(1,1)
cell.Hyperlink.Add(cell,'http://xxx')
2)Excel row/column count:
sht = xlsApp.ActiveSheet
sht.Columns.Areas.Count
sht.Rows.Areas.Count
*************************
[1]使用PyExcelera ......
Python http://www.python.org/download/ wxPython http://www.wxpython.org/download.php#binaries Vpython http://vpython.org/contents/download_windows.html Matplotlib http://sourceforge.net/projects/matplotlib/files/matplotlib/ PyGlet http://www.pyglet.org/download.html PyGame http://www.pyga ......
#将一些类型的文件压缩为7z.py
#for folder all file do 7z
import os
import sys
import distutils.file_util
def ImportOkFile():
if(os.path.isfile("D:\\Records\\将一些类型的文件压缩为7z_record.txt")==False):
f=open("D:\\Reco ......
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+'''</ ......