所读取的文件内容:
20160309,2839.41,2863.01,2811.72,2862.56,183355383,177072553984.00
20160310,2847.57,2863.18,2803.48,2804.73,138979461,141812416512.00
20160311,2781.60,2815.61,2772.55,2810.31,127247554,128450314240.00
- import codecs
- symbol = '999999'
- csvFile = '/home/www/stock/stockInfo/stockInfo_data_index/'+str(symbol)
- File = codecs.open(csvFile,'r','gb18030') #读取文件
- line_count = 0
- item = {}
- for line in File: #循环读取每行
- line_list = line.strip() #移除字符串(一行)头尾的空格
- item_count = 0
- for r in line_list.split(','): #把该行以逗号','分割后分别放进变量r
- if item_count == 0 : #每行第一列的日期放进变量date
- date = int(r)
- item_count +=1
- item[date] = line_list.split(',') #把当前整列的内容放进所对应日期(key)的值(value)的字典变量item中
- line_count +=1
- print(item[20160310])
执行python代码:
[root@localhost stockInfo]# py ps.py
['20160310', '2847.57', '2863.18', '2803.48', '2804.73', '138979461', '141812416512.00']