2013-06-05 77 views
0
def getPressAve(odbname): 
    odb=openOdb(odbname) 
    lastFrame=odb.steps['Step-1'].frames[-1] 
    pressure=lastFrame.fieldOutputs['CPRESS'] 
    press=[[0,0]] # sets the first element to [0,0] 

    for n in pressure.values: 
     gridPt=part1.nodes.getFromLabel(n.nodeLabel) 

     coord=assemb.getCoordinates(gridPt) 
     press.append([n.nodeLabel,n.data,coord]) 
     press=avePress=press[1:] # removes the first element 
     press.sort(Comp_X) 
     print ('pressure extracted') 

     index=0 
     while index<len(press): 
     sum=0 
     tally=0 

     if index!=0: 
      sum=sum+press[index-1][1] 
     tally=tally+1 

     if index!=1: 
      sum=sum+press[index-2][1] 
     tally=tally+1 

     if index!=2: 
      sum=sum+press[index][1] 
     tally=tally+1 

     if index<len(press)-1: 
      sum=sum+press[index+1][1] 
     tally=tally+1 

     if index<len(press)-2: 
      sum=sum+press[index+2][1] 
     tally=tally+1 

     average=sum/tally 
     avePress[index][1]=average 
     index=index+1 

    odb.close() 
    print ('pressure averaged') 
    return avePress 
+0

描述請 –

回答

0

你忘了適當縮進代碼:

def getPressAve(odbname): 
    odb=openOdb(odbname) 
    ... 
    print ('pressure averaged') 
    return avePress 

由於你沒有得到,該return關鍵字特色功能之外,因此錯誤:SyntaxError: 'return' outside function

1

在Python中,縮進很重要。正如,你定義一個名爲getPressAve功能,確實只有這個:

odb=openOdb(odbname) 

已經定義了你的功能後,你繼續做

lastFrame=odb.steps['Step-1'].frames[-1] 

和這樣以外的功能。這不是你想要的。解決方案是將該行之後的所有內容縮進到該級別,以便將這些行解釋爲該函數主體的一部分。