代码末尾的Python SyntaxError

时间:2014-06-18 17:15:17

标签: python syntax-error

我在以下代码中遇到同样的错误:

如果我要删除print语句

,这是一个类似的错误
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."
~                                                                               
~                                                                               
~                                                                               
~                                                                               
~    

1 个答案:

答案 0 :(得分:7)

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

你在这里错过了一个括号。

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