python操作excel
既然选择了远方,就必须日夜兼程 http://wrsuifeng.javaeye.com
Python代码
# Filename: excel.py
import os,sys,time
import win32com.client
import traceback
excel = win32com.client.Dispatch("Excel.Application")
filename = "D:\\test.xls"
try:
d1 = excel.Workbooks.Add()
sheet = d1.Sheets(1)
for i in xrange(1,10):
for j in xrange(1,10):
sheet.Cells(i,j).Value = str(i*j)
d1.SaveAs(filename)
except Exception, e:
print traceback.print_exc()
print e
excel.Quit()
相关文档:
def MergeSort(mylist, low, mid, high):
i = low
j = mid + 1
tmp = []
while i <= mid and j <= high:
if mylist[i] <= mylist[j]:
tmp.append(mylist[i])
i = i + 1
else:
tmp.append(mylist[j])
j = j + 1
......
我的环境是:Linux version 2.4.21-4.EL
(bhcompile@daffy.perf.redhat.com) (gcc version 3.2.3 20030502 (Red Hat
Linux 3.2.3-20)) #1 Fri Oct 3 18:13:58 EDT 2003 + Python2.6.4
本文结合我安装时候的问题,总结而成
用户目录如/home/liuguanyu/ , 保证用户有root权限
1,看看有没有安装
&nbs ......
参考链接:http://www.woodpecker.org.cn/diveintopython/functional_programming/dynamic_import.html
一 动态导入模块
Python的import不能接受变量,所以应该用 __import__函数来动态导入。
如下的代码无法正常导入模块
modules = ['OpenSSL', 'Crypto', 'MySQLdb', 'sqlite3', 'zope.interface', 'pyasn1', 'twisted ......
时常见到一些好的Python模块,如果不随时记下,等用的时候又是一阵乱翻,好在Python引用一个模块极其方便,OK,废话少说:
1. decimal
标准模块,2.4引入,用于浮点数的精确表示:
>>> 0.1 + 0.1 + 0.1 - 0.3
5.5511151231257827e-17
>>> from decimal import Decimal
>>> def _(x): retu ......
1.列表的递归---用于输出列表字符串中的每个元素 >>> def printList(L):
#如果为空,则什么都不做
if not L:
return
#如果是链表,则对第一个元素调用printList函数
& ......