def get_namecode(mypath='d:\\turnover_rate\\',zq_path='d:\\zd_pazq\\'): #提取股票代码名称对照表
import re
print('更新代码/名称对照表……')
#提取上海A股码表
file = zq_path + 'T0002\\hq_cache\\shm.tnf'
sh_namecode =[]
content = open(file,'r',encoding='utf8').read()
position = re.search('6'u'\d{5}',content)#获取第一个代码的位置
while position != None:
position = position.span()[0] #获取股票代码具体位置
code = int(content[position:position+6]) #提取股票代码
name = content[position+22:position+28].strip() #提取股票名称并去空格
name = name.split('\x00')[1] #去掉无用字符“\x00”
tup = (code,name) #打为元组
sh_namecode.append(tup)
content = content[position+29:] #截取文件的尾部