Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jerryw/9203927 to your computer and use it in GitHub Desktop.
Save jerryw/9203927 to your computer and use it in GitHub Desktop.
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格式的数据文件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment