where is best place for import statements?
Matthew Wilson
mwilson at sarcastic-horse.com
Thu Oct 23 14:14:57 EDT 2003
> Your cure would probably solve the problem, but I
> consider it much worse than the disease of having
> to remember to stick the proper import statement
> at the front of the module. You'll get at most one
> error in each module where you forget to do that.
>
> In general, importing a module at other than the
> module level is something you do in very specialized
> circumstances: when you need either a dynamic or
> a conditional import.
>
> John Roth
So, instead of scattering all those import statements throughout my
file, I ought to just put them at the top of the file, right after the
module description?
And, if I decide to do something like
from mymod import Circle
Then it's up to me to remember to first do
import math
Is that right?
More information about the Python-list
mailing list