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
Ïà¹ØÎĵµ£º
×Ô¼ºÓöµ½µÄÒ»¸öÎÊÌâ, WestGecoµÄ3DµØÕðÊý¾Ý, ÌáÈ¡µ¼º½Êý¾Ý:
#!/bin/env python
import sys
import struct
try:
f=open(sys.argv[1],'rb')
except (IOError,Exception):
print '''usage:
scriptname segyfilename
'''
&nbs ......
ÔÚLearning Python 3rd ÀïµÚÈý²¿·ÖÁ·Ï°ÌâÓеÀÌ⣺
1.c ±àдfor Ñ»·£¬¶ÔÓÚ×Ö·û´®S£¬·µ»ØÒ»¸öеÄÁÐ±í£¬ÆäÖаüº¬ÁË×Ö·û´®Ã¿¸ö×Ö·ûµÄASCIIÂë¡£
ÎÒµÄ˼·ÊÇ£º
for i in S:
L = [ord(i) for i in S] #Áбí½âÎöµÄ˼·
ÎҵĴíÎó˼·£º
for i in S:
L = L.append(ord(i))
Ìáʾ¿Õ¶ ......
>>> import time
>>> import datetime
>>>
now = time.localtime()
>>> now
(2006, 4, 30, 18, 7, 35,
6, 120, 0)
>>> type(now)
<type 'time.struct_time'>
>>>
str_now = time.strftime("%m/%d/%Y %X", now )
>>>
str_n ......
ºÜ³¤µÄÒ»¶Î´úÂ룬µ«ºÜÇå³þ¡£¹þ¹þ¡£
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'): ......