我一直在尝试运行一个软件,但由于我不是python的专家,我不知道这个语法错误是什么。我收到以下错误消息:
Traceback (most recent call last):
File "rnaQUAST.py", line 29, in <module>
from metrics import TranscriptsMetrics
File "/NFS/home/ffalcon/TOOLS/rnaQUAST1.4.0/metrics/TranscriptsMetrics.py", line 6, in <module>
from general import UtilsCoverage
File "/NFS/home/ffalcon/TOOLS/rnaQUAST1.4.0/general/UtilsCoverage.py", line 234
covered_isoform_fraction_max = {id_isoform: isoforms_covered_fraction[id_isoform] for id_isoform in ids_isoforms_max}
^
SyntaxError: invalid syntax
答案 0 :(得分:0)
dict comprehension
向上运行python2.7。根据你的评论,我相信你从python2.6得到如下错误:
python2.6的
Python 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> mydict = {"a":1}
>>> mylist = ["a"]
>>> {x:mydict[x] for x in mylist}
File "<stdin>", line 1
{x:mydict[x] for x in mylist}
^
SyntaxError: invalid syntax
Python2.7
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> mydict ={"a":1}
>>> mylist=["a"]
>>> {x:mydict[x] for x in mylist}
{'a': 1}
这是我的解决方案:
>>> data = dict((x,mydict[x]) for x in mydict)
>>> data
{'a': 1}