Importing modules

e4me4m at gmail.com e4me4m at gmail.com
Wed Jan 7 12:29:06 EST 2009


Coming from a scripting background where we used to write everything
into one script, I'm now going modular with Python. I place related
functions in one module, and other functions in other modules.

This all works OK, but I'm a bit confused about importing modules from
the standard library. For example, say 3 of my 12 modules use os and
os.path. Right now, I have import statements in all 3 modules that
import both os and os.path. This seems wrong to me.

I read the docs and understand that before loading a module that
Python is smart enough to look and see if it's already loaded, so
there is no performance issue (it would seem), but I was thinking
there is probably a way to load all the modules I need in some orderly
fashion without having these multiple import statements in my separate
modules.

Could someone point me to some docs that explain the Python way of
loading modules when breaking old, big (everything in one script) into
more manageable modular scripts?

Thanks,

e4m



More information about the Python-list mailing list