我有以下代码:优化Python代码
inputFile = open('C:/Abaqus_JOBS' + JobDir + '/' + JobName + '-3_4.inp', 'r')
for line in inputFile:
fileData.append([x.strip() for x in line.split(',')])
fel=0
for row,data in enumerate(fileData):
if data[0]=='*Node':
row_nodes = row #number of the row when data='*Node'
if data[0]=='*Element' and fel==0:
row_elements2 = row
fel=1
for row,data in enumerate(fileData[row_nodes + 1:row_elements2]):
nodes.append(data) #data between '*Nodes' and '*Element'
但是,它的运行速度非常缓慢,外部程序的蟒蛇interpeter(分钟)(我要在这里运行的脚本,因为我需要访问该计划产生的结果数据库)。我怎样才能优化它?
编辑: 我关闭inputFile
的代码的末尾:inputFile.close()
在''....什么? – Patashu
档案有多大?你确定你在阅读完文件后正确关闭文件吗? – jozzas
@Patashu,jozzas:编辑过的问题。 – jpcgandre