简体   繁体   中英

Syntax error when importing CSV file (Python)

I'm fairly new to Python and am using it for parsing some data. For some reason when I run:

import numpy as 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)

I am getting a syntax error. If someone could help me I would be forever grateful. This is the file name: 7202HEVRK3 (and it's a CSV format).

Edit: The syntax error is "invalid syntax"

The syntax error is occurring because you are trying to assign a value to - (the minus operator). By changing - to _ the syntax error will be removed as python reads _ as a placeholder. It is likely that you intended to do this but forgot to hit the shift button. Also remove the - from e-value and replace it with a _ .

Try the following:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM