Possible Duplicate:
Help with Python UnboundLocalError: local variable referenced before assignment
In python3, I have two classes, one for DNA and one for RNA. I would like the DNA class to have a method that takes the DNA sequence (an instance variable of DNA, self.sequence), changes it into an RNA sequence (easily done with a for loop), and then creates an RNA object with the new sequence as an instance variable.
At the same time, I would like the RNA class to have a method that does the opposite (That is, it takes the RNA sequence, produces a corresponding DNA sequence, and then creates a DNA object that uses the sequence as an instance variable.)
My method for making RNA from DNA is as follows:
def transcribe(self):
RNAseq=''
for base in self.sequence:
if base=='A' or base=='C' or base=='G':
RNAseq=RNAseq+base
if base=='T':
RNAseq=RNAseq+'U'
RNA=RNA(RNAseq,self.name+'RNA')
return RNA
This code gives me the error: UnboundLocalError: local variable 'RNA' referenced before assignment
Can what I want to do be done?
RNAthe name of your RNA class?