Propagate import for all modules in a package.

Phil phily05 at gmail.com
Fri Jul 17 19:28:13 CEST 2009


I'm really new to Python and I am absolutely stumped trying to figure
this out. I have searched plenty, but I am either searching for the
wrong keywords or this isn't possible.

What I want to do is have one import be global for the entire package.
Here is an example...

<package>
  __init__.py
  module1.py
  module2.py
  ...
  moduleN.py

I was thinking that I could just, for example, 'from datetime import
datetime' in __init__.py and have the ability to use 'datetime'
anywhere in any of the modules in 'package'.

This didn't work for me. Did I just do something wrong? Is what I am
trying to do possible?

Thanks in advance.



More information about the Python-list mailing list