我有必须使用图形库读取和绘制的数据。除了我想跳过第一个列表外,我能够将数据拆分成一个列表。
from graphics import *
def main():
data = input("Type in the filename: ")
infile = open(data, "r")
for aline in infile:
# I try using read() but I get one output
data1 = infile.readline()
dataLst = aline.split('","')
print(dataLst[1])
main()
输出:
close <--- How to skip this line?
720.11
720.1100
721.0700
这是一个数据示例,粗体是我要打印的数据: “日期”,“收盘”,“交易量”,“开盘”,“高”,“低”
"16:00","720.11","1,919,799","720.71","723","716.68" "2012/12/19","720.1100","1918493.0000","720.7100","723.0000","716.6800" "2012/12/18","721.0700","3004838.0000","716.6000","729.1000","715.0500"
请您参考如下方法:
可以使用next()函数跳过第一行:
with open('data.txt') as f:
next(f) # Skip one line
for line in f:
print line
更新
我不知道为什么原发布者不喜欢 next(),但如果 PO 坚持,请改用 readline():
with open('data.txt') as f:
f.readline() # Skip one line
for line in f:
print line
