[英]“Can't assign to operator” error using dictionary
I'm trying to use a simple dictionary to replace values on each line of a text file with their respective dictionary values but am getting the "can't assign to operator error" at the first line of the dictionary. 我正在尝试使用一个简单的词典来将文本文件的每一行中的值替换为其各自的词典值,但是在词典的第一行得到“无法分配给操作员错误”。 Below is what I have so far... 以下是我到目前为止所拥有的...
#!/usr/bin/python
import sys
funcat-cog = {'Translation, ribosomal structure and biogenesis': 'J',
'RNA processing and modification': 'A',
'Transcription': 'K',
'Replication, recombination and repair': 'L',
'Chromatin structure and dynamis': 'B',
'Cell cycle control, cell division, chromosome partitioning': 'D',
'Defense mechanisms': 'V',
'Signal transduction mechanisms': 'T',
'Cell wall/membrane/envelope biogensis': 'M',
'Cell motility': 'N',
'Intracellular trafficking and secretion': 'U',
'Posttranslational modification, protein turnover, chaperones': 'O',
'Energy production and conversion': 'C',
'Carbohydrate transport and metabolism': 'G',
'Amino acid transport and metabolism': 'E',
'Nucleotide trnasport and metabolism': 'F',
'Coenzyme transport and metabolism': 'H',
'Lipid transport and metabolism': 'I',
'Inorganic ion transport and metabolism': 'P',
'Secondary metabolites biosynthesis, transport and catabolism': 'Q',
'General function': 'R',
'Function unknown': 'S',
'.': '.'}
fil = open(sys.argv[1])
for line in fil:
linearr = line.strip('\n')
for k,v in funcat-cog.items():
print v
Can anyone help me with figuring out what is wrong? 谁能帮助我找出问题所在? Could it be a formatting error? 可能是格式错误?
Identifiers such as funcat-cog
can not have hyphens. 诸如funcat-cog
标识符不能带有连字符。 Fix the error by changing the variable name to something like funcat_cog
. 通过将变量名更改为funcat_cog
类的错误来修复该错误。
Python interprets funcat-cog
as the difference of some variable named funcat
minus some variable called cog
. Python将funcat-cog
解释为某个名为funcat
变量减去一个名为cog
变量之差。 The error message, "Can't assign to operator"
is saying that you can't take a difference of two variables and assign it a new value at the same time. 错误消息"Can't assign to operator"
表示您不能同时使用两个变量并为其分配新值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.