导入CSV文件时出现语法错误(Python)

时间:2016-05-31 15:27:25

标签: python csv numpy

我对Python很新,并且正在使用它来解析一些数据。出于某种原因,当我跑:

将numpy导入为np

def main():

    try:
        sequencename, modelaccession, modelname, bitscore, e-value, -, hmmstart, hmmend, hmmlength, strandofhit, alignmentstart, alignmentend, envelopestart, envelopeend, sequencelength, descriptionoftargetsequence = np.loadtxt(('7202HEVRK3.csv')
                                                                                                                                                                                                                                    ,delimiter= ','
                                                                                                                                                                                                                                    ,unpack = True
                                                                                                                                                                                                                                    ,dtype='string')

        print sequencename

    except Exception, e:
        print str(e)

我收到语法错误。如果有人能帮助我,我将永远感激不尽。这是文件名:7202HEVRK3(它是CSV格式)。

编辑:语法错误是“语法无效”

1 个答案:

答案 0 :(得分:2)

发生语法错误是因为您尝试将值分配给-(减号运算符)。通过将-更改为_,当python将_作为占位符读取时,将删除语法错误。您可能打算这样做但忘记按下换档按钮。 同时从-移除e-value,并将其替换为_

尝试以下方法:

try:
    sequencename, modelaccession, modelname, bitscore, e_value, _, hmmstart, hmmend, hmmlength, strandofhit, alignmentstart, alignmentend, envelopestart, envelopeend, sequencelength, descriptionoftargetsequence = np.loadtxt('7202HEVRK3.csv',
                                                                                                                                                                                                                                delimiter= ',',
                                                                                                                                                                                                                                unpack = True,
                                                                                                                                                                                                                                dtype='string')

    print sequencename

except Exception, e:
    print str(e)