[Biopython-dev] Basic python question with regard to Unigene parser

Sean Davis sdavis2 at mail.nih.gov
Thu Oct 26 12:09:43 UTC 2006


Let me start off by saying that I am a python newbie after working in perl for 
the last few years.  I am working on a Unigene flat file parser.  In my 
scanner, I have a construct that looks like:

        for line in handle:
            tag = line.split(' ')[0]
            line = line.rstrip()
            if tag=='ID':
                consumer.ID(line)
            if tag=='GENE':
                consumer.GENE(line)
            if tag=='TITLE':
                consumer.TITLE(line)
            if tag=='EXPRESS':
                consumer.EXPRESS(line)
            ....

Since I am setting things up so that there is a 1:1 correspondence between the 
"tag" and the consumer method, is there an easy way to reduce this long set 
of IF statements to a simple mapping procedure that maps a tag to the correct 
method?

Sorry for the naive question....

Thanks,
Sean



More information about the Biopython-dev mailing list