[英]Syntax error when importing CSV file (Python)
I'm fairly new to Python and am using it for parsing some data.我对 Python 相当陌生,正在使用它来解析一些数据。 For some reason when I run:出于某种原因,当我运行时:
import numpy as np将 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)
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).这是文件名:7202HEVRK3(它是一种 CSV 格式)。
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.通过将-
更改为_
语法错误将被删除,因为 python 将_
作为占位符读取。 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 _
.还要从e-value
删除-
并将其替换为_
。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.