#해당 장의 종목들을 종목코드/종목이름 형식의 csv파일로 저장합니다. 인자는 파일위치,파일명,장 타입(#1 = kospi, 2 = kosdaq 추정)
#adress='c:\\Users\\yeonwoo\\PycharmProjects\\daishin20201003'
#filename='kospi'
#market_type = 1
#win32com.client가 import 되어있지 않다면 import 하셔야합니다.
def code_n_name_excel(adress,filename,market_type):
#import win32com.client
file_location = adress+'\\'+filename+'.csv'
instCpCodeMgr = win32com.client.Dispatch("CpUtil.CpCodeMgr")
#1 = kospi, 2 = kosdaq
#codeList = instCpCodeMgr.GetStockListByMarket(2)
codeList = instCpCodeMgr.GetStockListByMarket(market_type)
kospi = {}
for code in codeList:
name = instCpCodeMgr.CodeToName(code)
kospi[code] = name
#f = open('c:\\Users\\yeonwoo\\PycharmProjects\\daishin20201003\\kospi.csv', 'w')
f = open(file_location, 'w')
for key, value in kospi.items():
f.write("%s,%s\n" % (key, value))
f.close()