2017-06-20 10 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以下の2番目のステートメントを無視しているように見えるので、構文に問題があるかどうか疑問に思っています。パイソン3.5

+0

あなたは( 'BSlist'の内容)データのサンプルを示してもらえますか?ここhttps://i.stack.imgur.com/LSA1f.png –

+0

リストに印刷されるべきではないデータの一例を示す画像へのリンクです。右側を見ると、値が2.000未満でないことがわかります...このデータを除外しようとしていますが、出力に含まれています。 – rprog

+0

基本的に、 'BSlist'は文字列のリストです。それぞれのリストには2つの浮動小数点数が含まれており、そのうち2番目の数字だけが対象となります。 –

答えて

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

値=フロートで開始としてヘッダを含む62行を取得するために、カウントを使用します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