易截截图软件、单文件、免安装、纯绿色、仅160KB

Python 处理excel并转为table

使用xlrd

读取,xlrd的下载及安装可以参看:
Python
"xlrd" package for extracting data from Excel files
---------------------------------------------------------------------------------
#coding=utf-8
import xlrd
import os, types, datetime
#excel存放目录
dir = u'D:\\temp\\excel'
#生成html存放目录,需要事先建立
htmlroot = u'D:\\temp\\html'
#excel从1899/12/31计算时间
__s_date = datetime.date(1899, 12, 31).toordinal() - 1
#读取时间格式的单元
def getdate(date):
    if isinstance(date, float):
        date = int(date)
    d = datetime.date.fromordinal(__s_date + date)
    return d.strftime("%Y-%m-%d")
#遍历文件夹
for root, dirs, files in os.walk(dir):
    for file in files:
        #生成excel文件路径
        path = os.path.join(root, file)
        print u'converting...   ' + path
      
        book = xlrd.open_workbook(path) #打开excel文件
      
        #遍历excel文件中的sheet
        for shn in range(book.nsheets):
            sh = book.sheet_by_index(shn)
            #判断该表是否为空
            if sh.nrows == 0:
                continue
          
            #搜索“路径”列
 &nbs


相关文档:

Python语言概览

python
语言概览
 
python
脚本可以处理外部传进来的参数 即sys.argv[] 
,argv[]
的使用与linux
下相同
python
本身是解释语言,可以对输入的式子求值。python
支持的对象如整数都是立即数,此外他支持复数,及对四则运算解释。
ptyhon
支持字符串,放在单/
双引号内,字符串是数组,可以通过[i: ......

用Python提取文件夹下的特定扩展名的文件

                用Python提取文件夹下的特定扩展名的文件
      不知道什么时候,网闲着没用,挂了个linux的视屏教程,里面有很多个文件夹,有很多无关的文件。这对于像我没收藏垃圾文件癖好的人来说,简直是 ......

python中package机制的两种实现方式


当执行import
module时,解释器会根据下面的搜索路径,搜索module1.py文件。
1) 当前工作目录
2) PYTHONPATH中的目录
3) Python安装目录
(/usr/local/lib/python)
事实上,模块搜索是在保存在sys.path这个全局变量中的目录列表中进行搜索。
sys.path会在解释器开始执行时被初始化成包含:
1)当前工作目录
2) PYT ......

用Python直接写UTF 8文本文件

当我们这样建立文件时
f =
file('x1.txt', 'w')
f.write(u'中文')
f.colse()

接结果应该是类似
    f.write(u'中文')
UnicodeEncodeError: 'ascii'
codec can't encode characters in position 0-16: ordinal not in
range(128)
要直接写 utf-8 文件怎么办呢?
import codecs
f = codecs. ......

python读取目录下文件并生成日志

很长的一段代码,但很清楚。哈哈。
import os
from time import strftime
stamp=strftime("%Y-%m-%d %H:%M:%S")
logfile = 'F:\\test\\m-php-framework\\tmp\logs\\error_report.log'
path = 'F:\\test\\'
files = os.listdir(path)
bytes = 0
numfiles = 0
for f in files:
if f.startswith('t'): ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号