[英]How to start writing to a text file 2 lines in
I'm currently opening a csv file and writing it to a new .h file. 我目前正在打开一个csv文件,并将其写入新的.h文件。 However, I would like to write everything BUT the first two lines of the csv file.
但是,我想将所有内容都写到csv文件的前两行中。
How can I start writing two lines in? 如何开始写两行?
import csv
newheader2 = open("ffile2.h", 'w')
with open("pcf_gras.csv") as newcsvfile:
readCSV = csv.reader(newcsvfile, delimiter= ',')
newheader2.write("Heading Comment Section")
for item in readCSV:
#name = item[2]
#newheader2.write(name)
#print(item[2], item[5])
newheader2.write("#define ")
newheader2.write(item[2])
newheader2.write(" ")
newheader2.write(item[5])
newheader2.write("\n")
After you create your readCSV
object, you can skip two lines by calling: 创建
readCSV
对象后,可以通过调用以下内容跳过两行:
next(readCSV)
next(readCSV)
Then when you do for item in readCSV:
, it will start from that position in the file. 然后,当您
for item in readCSV:
,它将从文件中的该位置开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.