Where to place imports

John [H2O] washakie at gmail.com
Fri Jan 23 11:32:10 EST 2009


Hello, Im writing some modules and I am a little confused about where to
place my imports...

I don't really do any class programming yet, just defining a bunch of
functions, so presently I have something along the lines of:

import sys
import os
import traceback


def Foo1(a,b):
   import numpy
   import datetime
   return c

def Foo2(a,b):
   import datetime

   c = Foo1(a,b)
   return c

etc...

Above obviously just for the form, but the point is, in some cases I may
import modules twice, but other times I may not use them at all, so should I
import everything into the main module? Or individually import them into
functions. Is there a performance penalty either way? 

Pointers to a good reference are appreciated...


-- 
View this message in context: http://www.nabble.com/Where-to-place-imports-tp21627895p21627895.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list