2014-06-18 38 views
-1

我不斷收到同樣的錯誤以下代碼結尾:的Python的SyntaxError在代碼

下面是一個類似的錯誤,如果我是刪除打印語句

File "./MIcalc.py", line 31 

             ^
SyntaxError: invalid syntax 

我知道這是說,有在文件的最後一個語法錯誤,但我不知道如何糾正它:/

我使用Python 2.7版和錯誤在行的任何一行代碼仍然存在31

#!/usr/local/bin/python 
DIR = '/home/sbird/lobSTR/output/output.txt' 

def makeAlleleList(ALLREADS): 
    alleleList = [] 
    ALLREADS_split = ALLREADS.split(";") 
    allele = [x.split("|") for x in ALLREADS_split] 
    [alleleList.append(x[0]) for x in allele] 
    return alleleList 

def makeCovThresh(ALLREADS): 
    covThreshList = 0 
    ALLREADS_split = ALLREADS.split(";") 
    allele = [x.split("|") for x in ALLREADS_split] 
    for x in allele: 
      covThreshHold += int(x[1]) 
    return covThreshList 

f = open("write_MI_out.txt","w") 

for line in open(DIR): 
    column = line.split("\t") 
    ALLREADS = column[2].split("'") 
    motherList = makeAlleleList(ALLREADS[1]) 
    fatherList = makeAlleleList(ALLREADS[3]) 
    sonList = makeAlleleList(ALLREADS[5]) 
    covThresh = makeCovThresh(ALLREADS[5]) 
    if len(sonList) < 3: 
      if set(motherList) & set(fatherList) & set(sonList): 
        f.write("{0} \n".format(covThresh) 
        print "wrote to file" 
f.close() 
print "Fin." 
~                    
~                    
~                    
~                    
~  
+2

存在您的問題 - 「做某事」不是有效的Python代碼。 – Kevin

+0

我遇到過幾次發現錯誤的人說,他們在某條特定線路上時,他們實際上位於一條或兩條上述線路上。包含所有代碼至少10行,從錯誤位置開始 – samrap

+0

我是否缺少閉括號? 我在vim工作,我是否需要重新將代碼寫入另一個保存的文件 – Sean

回答

7
   f.write("{0} \n".format(covThresh) 

此處缺少括號。

   f.write("{0} \n".format(covThresh))