2017-06-20 106 views
0
x = y = 0 #sorts the data into spin up or spin down, then in required eV range 
for x in range(0,len(BSlist)): 
if 'Spin.Up' in BSlist[x]: 
    for y in range (x+1,x+(Count)): 
     if (float(BSlist[y].split()[1]) >= -2.0) and (float(BSlist[y].split()[1]) <= 2.0): 
      UpList1.extend(BSlist[x:(x+(Count))]) 
      x = ((x // Count) * (Count)) + Count 
      continue 
if 'Spin.Down' in BSlist[x]: 
    for y in range (x+1,x+(Count)): 
     if (float(BSlist[y].split()[1]) >= -2.0) and (float(BSlist[y].split()[1]) <= 2.0): 
      DnList1.extend(BSlist[x:(x+(Count))]) 
      x = ((x // Count) * (Count)) + Count 
      continue  

UpList2 = []#changing to csv form 
x = y = 0 
for x in range(0,Count): 
UpList2.append(str(x)) 
if x != 0: 
    y = x 
    UpList2[x] = UpList2[x] + '\t' + UpList1[x].split()[0] + '\t' + 
UpList1[x].split()[1] 
    while y in range(0,len(UpList1)): 
     UpList2[x] = UpList2[x] + '\t' + UpList1[y].split()[1] 
     y = y + Count 
if 'Spin.Up' in UpList1[x]: 
    while y in range(0,len(UpList1)): 
     UpList2[x] = UpList2[x] + '\t' + UpList1[y][UpList1[y].find('Band'): 
(UpList1[y].find('Band')+9)] 
     y = y + Count 

程序的這一部分以預先存儲在一個列表中,並對其進行排序成兩個單獨的列表60個的數據點不排序基於設定的範圍的值。之後,它應該通過列表中的每個數據點並檢查它們是否在大於或等於-2.0且小於或等於2.0的範圍內。但是,它只輸出介於-2.0和8.0之間的數據。我們想知道這是否是語法問題,因爲它似乎忽略了小於或等於2.0的第二條語句。蟒3.5使用布爾運算符

+0

能告訴你數據的樣本(BSlist'的'內容)? –

+0

https://i.stack.imgur.com/LSA1f.png 下面是一張圖片的鏈接,該圖片顯示了不應打印到列表中的數據示例。如果你看右側,你會發現沒有一個值低於2.000 ...我們試圖排除這些數據,但它包含在輸出中。 – rprog

+0

所以,基本上,'BSlist'是一個字符串列表,每個字符串都包含兩個浮點數,並且只有這些數字中的第二個是感興趣的,對嗎? –

回答

0

所以,除非我誤解了問題(這是完全可能的),它歸結爲:

for line_num, line in enumerate(BSlist): 
    # look for Spin.Up or Spin.Down header 
    if 'Spin.Up' in line: 
     destination = UpList1 
    elif 'Spin.Down' in line: 
     destination = DnList1 
    else: 
     continue 

    # header found 
    # analyze next Count lines 
    series = BSlist[line_num+1:line_num+Count] 
    for line2 in series: 
     value = float(line2.strip().split()[1]) 
     if -2.0 <= value <= 2.0: 
      destination.append(line) 
      destination.extend(series) 
      destination.append('\n') 
      break 
+0

value = float(line2.strip().split()[1]) ValueError:無法將字符串轉換爲float:'Axes(0.125, 0.1; 0.775x0.8)' 錯誤信息 – rprog

+0

對不起,看起來像我超量程的上限。現在它應該工作。 –

+0

它仍然給出相同的錯誤, value = float(line2.strip()。split()[1]) ValueError:無法將字符串轉換爲float:'Axes(0.125,0.1; 0.775x0.8)' – rprog