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>)
>>>>>>
相关文档:
既然选择了远方,就必须日夜兼程 http://wrsuifeng.javaeye.com
Python代码
# Filename: excel.py
import os,sys,time
import win32com.client
import traceback
excel = win32com.client.Dispatch(" ......
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 com 报告
http://appofis.javaeye.com/blog/417446
python 操作ms office 生成报告相关总结
I. 项目中需要生成word和excel报告,通常有两种方法:基于字符串拼接以及COM调用。
1) 字符串拼接生成office文档的原理: office文档本身可以体现为xml文件格式,尤其是MS Excel
2003,我们可以自己将一 ......
http://www.autohotkey.com/forum/topic53773.html
Q:I am searching for is a way to execute AHK commands from a Python script. Is this possible?
A:Yes. Here is an example.
tested with python2.6, requires AutoHotkey.dll in the working directory or path...
ahkpython.py:
#Persistent
dllc ......
#将一些类型的文件压缩为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 ......