how to improve efficiency of this Python code
Question: I have written a simple code in ABAQUS PDE to export results to csv files. I
put a part of it here and I am wondering how I may improve its efficiency.

I am so appreciated for your valuable comments.

    
    
    from odbAccess import *
    from abaqusConstants import *
    
    outputname='job-23.odb'
    
    odb=openOdb(outputname)
    
    myAssembly=odb.rootAssembly
    
    % Defining number of elements
    
    nofl=46
    
    s1=open('s1.csv','w')
    
    %Defining lenght of steps
    lengthsteps=len(odb.steps.keys())
    
    for j in range(nofl):
    
        for i in range(lengthsteps-1):
            step=odb.steps.keys()[i]
            s=odb.steps[step]
            jj=odb.steps[opstep].historyRegions.keys()[j]
            sdata=s.historyRegions[jj].historyOutputs['S11'].data
            l=len(sdata)
            for k in range(l-1):
                s1.write('%10.4E\n' % sdata[k][1])
    
    
    s1.close()
    


Answer: Something which you should **not** use in python is:

    
    
    objectNr = len(myObjects)
    for i in range(objectNr-1):
      a = myObjects[i]
      print a
    

Something like this would be better:

    
    
    for myObject in myObjects:
       print myObject
    

In your case would it be maybe easier, when you iter over odb.steps.

    
    
    for step in odb.steps:
      s=odb.steps[step]
      ...
    

Much shorter better to read and it is the python way.

