basic class question..
Pyrot
sungsuha at gmail.com
Sun Nov 15 07:40:00 EST 2009
class rawDNA:
import string
trans = string.maketrans("GATC","CTAG")
def __init__(self, template = "GATTACA"):
self.template = template //shouldn't this make "template"
accessible within the scope of "rawDNA"??
def noncoding(self):
print template.translate(trans) //
>>>test = rawDNA()
>>>test.noncoding()
Traceback (most recent call last):
File "<pyshell#29>", line 1, in <module>
test.noncoding()
File "<pyshell#25>", line 7, in noncoding
print template.translate(trans)
NameError: global name 'template' is not defined
I'm curious .. what am I doing wrong??
P.S
class rawDNA:
import string
trans = string.maketrans("GATC","CTAG")
def __init__(self, template = "GATTACA"):
self.template = template
def noncoding(self):
print self.template.translate(trans)
this works as intended.
Thanks in advance
More information about the Python-list
mailing list