inputFile = "AllEvents.txt" # give the path to the file that contain all the events
eventInfo = "" # create a string to hold event info
eventCounter = 0
fileId = 0
subFile= open("Events" + str(fileId) + ".txt","w+") # create the sub file that you need
with open(inputFile) as fileContent:
for line in fileContent:
if not line.strip(): # strip white spaces to be sure is an empty line
subFile.write(eventInfo + "\n") # add event to the subFile
eventInfo = "" # reinit event info
eventCounter += 1
if eventCounter == 700:
subFile.close()
fileId += 1
subFile = open("Events" + str(fileId) + ".txt","w+")
eventCounter = 0
else:
eventInfo += line
subFile.close()
原则上你可以这样做:
最后你会有一个文件列表,每个文件有700个事件:Events0.txt,Events1.txt。。。你知道吗
相关问题 更多 >
编程相关推荐