basic class question..

Pyrot sungsuha at
Mon Nov 16 01:26:59 CET 2009

On 11월15일, 오후9시52분, "Diez B. Roggisch" <de... at> wrote:
> Pyrot schrieb:
> > class rawDNA:
> >    import string
> Importing here is unusual. Unless you have good reasons to do so, I
> suggest you put the imports on top of the file.
> >    trans = string.maketrans("GATC","CTAG")
> >    def __init__(self, template = "GATTACA"):
> >            self.template = template  //shouldn't this make "template"
> > accessible within the scope of "rawDNA"??
> No.
> >    def noncoding(self):
> >            print template.translate(trans)  //
> This needs to be
>    print self.template.translate(trans)
> Thes scopes insied a class are only the method-locals (to which the
> parameters count of course), and globals.
> Diez

Thanks for the tip Diez.

(Tthe core reason that I'm bothering with this at all is because I
heard imports are costly(in time, space, processing power). If this
turns out to be a non-issue, than my questions regarding Imports are
all moot :->)

I forgot to write about my second question which was:

what happens when I use the import statement within a class/function
I'm thinking either
1) It imports during the class/function declaration
2) It imports the first time a class/function call(x = rawDNA() )

But if it's 2) then is the import valid outside of the function/class?
what happens when the last function reference is removed?(del x)

obviously this is a lot of questions...

I respect your(or anyone who would like to help me) time, so all I ask
is some kind of document or "Best practices" guide dealing all about
"import".(because sadly,
does not ask my questions)

More information about the Python-list mailing list