使用字典"无法分配给运算符"错误

Rus*_*uss 2 python dictionary

我正在尝试使用一个简单的字典来替换文本文件的每一行上的值与它们各自的字典值,但是在字典的第一行得到"无法分配给操作符错误".以下是我到目前为止的情况......

#!/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
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我找出问题所在吗?这可能是格式化错误吗?

unu*_*tbu 5

标识符funcat-cog不能有连字符.通过将变量名称更改为类似的方法来修复错误funcat_cog.

Python将funcat-cog一些变量的差异解释为funcat减去一些被称为变量的变量cog.错误消息"Can't assign to operator"表示您不能对两个变量进行区分并同时为其分配新值.