Created
April 22, 2012 09:21
-
-
Save rainly/2462923 to your computer and use it in GitHub Desktop.
通达信股票日线数据格式读取程序--python 参考: http://alantop.5166.info/gpdatasoft/gpformat/gpformat.htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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