[Tutor] Possible to import imports?

Hansen, Mike Mike.Hansen at atmel.com
Mon Jun 23 22:40:39 CEST 2008


> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of Rob Kirkpatrick
> It was mostly an exercise in understanding import 
> orders/precedence but I thought I might be able to use it to 
> simplify imports for modules within a package that might all 
> use the same or similar standard imports.  The one I see a 
> lot of is modules in the package routinely importing os and 
> sys so I thought that if I could just import them once at the 
> highest package level then just have the modules import their 
> parent package, things would be cleaner.  You make a good 
> point about that causing more confusion than it's worth 
> though, so I'll shelve that idea for the time being.
> Funny though that I did try using something like foo.datetime 
> but I must have buggered up something cause I couldn't get it 
> to work...
> Thanks Kent!

Someone on the list can correct me if I'm wrong, but I think
performing imports on the same module doesn't have any negative
impact. I try to keep each of my modules importing what they need. If
my main program also needs that module, I'll import it in the main
program. I think it helps for readability. Also each module can stand
on it's own and not use another modules import of other modules.


More information about the Tutor mailing list