2

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?

Russ
  • 103
  • 9

1 Answers1

5

Identifiers such as funcat-cog can not have hyphens. Fix the error by changing the variable name to something like funcat_cog.

Python interprets funcat-cog as the difference of some variable named funcat minus some variable called 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.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677