2017-06-20 65 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