zhehao
8/23/2014 - 1:02 AM

通达信股票日线数据格式读取程序

from struct import *
ofile=open('sz000680.day','rb')
buf=ofile.read()
ofile.close()

ifile=open('sz000680.txt','w')
num=len(buf)
no=num/32
b=0
e=32
line=''

for i in xrange(no):
   a=unpack('IIIIIfII',buf[b:e])
   line=str(a[0])+' '+str(a[1]/100.0)+' '+str(a[2]/100.0)+' '+str(a[3]/100.0)+' '+str(a[4]/100.0)+' '+str(a[5]/10.0)+' '+str(a[6])+' '+str(a[7])+' '+'\n'
   print line
   ifile.write(line)
   b=b+32
   e=e+32
ifile.close()







将文件保存为: tdx.py
然后再到通达信文件路径下:c:\tdx\Vipdoc\sz\lday将所要下载的股票代码COPY到当前路径下与tdx.py文件在同一路径下。
最后,运行:python tdx.py 即可在当前路径下生成TXT格式的数据文件。