import random
import csv
csvfile=open(r"g:\code\test3.csv", 'w',newline='')
writer = csv.writer(csvfile)
writer.writerow(['code', 'name'])
data = [
('\t002466', '天齐锂业'),
('\t300432', '富临精工'),
('\t603799', '华友钴业'),
('\t300073', '当升科技'),
('\t300618', '寒锐钴业'),
('\t002812', '恩杰股份'),
('\t300014', '亿纬锂能'),
('\t600884', '杉杉股份'),
('\t600303', '曙光股份'),
('\t688138', '清溢光电'),
('\t000021', '深科技'),
('\t600703', '三安光电'),
('\t002405', '四维图新'),
('\t603893', '瑞芯微'),
('\t688002', '睿创微纳'),
('\t000009', '中国宝安'),
('\t603088', '宁波精达'),
('\t002169', '智光电气'),
('\t300548', '博创科技'),
('\t688099', '晶晨股份'),
('\t300115', '长盈精密'),
('\t002772', '众兴菌业'),
('\t300130', '新国都'),
('\t688368', '晶丰明源'),
('\t002180', '纳思达'),
('\t603286', '日盈电子'),
('\t002288', '超华科技'),
('\t002371', '北方华创'),
('\t002436', '兴森科技'),
('\t002618', '丹邦科技'),
('\t002916', '深南电路'),
('\t600127', '金健米业'),
('\t603336', '宏辉果蔬'),
('\t000716', '黑芝麻'),
('\t600313', '农发种业'),
('\t000713', '丰乐种业'),
('\t601952', '苏垦农发'),
('\t600598', '北大荒'),
('\t000998', '隆平高科'),
('\t002041', '登海种业'),
('\t002385', '大北农'),
('\t300511', '雪榕生物'),
('\t600354', '*ST敦种'),
('\t600108', '亚盛集团'),
('\t601118', '海南橡胶'),
('\t300087', '荃银高科'),
('\t300189', '神农科技'),
('\t600540', '新赛股份'),
('\t600506', '香梨股份'),
('\t600359', '新农开发'),
('\t600371', '万向德农'),
('\t603078', '江化微'),
('\t688028', '沃尔德'),
('\t300263', '隆华科技'),
('\t002876', '三利谱'),
('\t603203', '快克股份'),
('\t603920', '世运电路'),
('\t603773', '沃格光电'),
('\t002585', '双星新材'),
('\t002387', '维信诺'),
('\t603010', '万盛股份'),
('\t300706', '阿石创')
]
writer.writerows(data)
csvfile.close()
#读CSV文件:
# fr=open(r"g:\code\test2.csv")
# while True:
# line=fr.readline()
# if len(line)==0:
# break
# print(line)
# fr.close
def load_word_file():
word_list = []
with open(r"g:\code\test3.csv",'r') as csvfile:
content = csv.reader(csvfile)
for i in content:
word_list.append(tuple(i))
return word_list
def examination():
word_list = load_word_file()
examination_quantity = 100
if len(word_list) < examination_quantity:
examination_quantity = len(word_list)
for code, name in random.sample(word_list, examination_quantity):
print('\n')
print(name)
answer = input('Please translate the word, your answer is? ')
if answer == code.strip('\t'):
print('Its correct.')
else:
append_word(code, name)
print('wrong, the correct answer is', code)
def append_word(code, name):
with open(r"g:\code\test3.csv", 'a', newline = '') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([code, name])
if __name__ == '__main__':
examination()
python3背证券代码程序
最新推荐文章于 2020-06-16 13:58:30 发布