Newbie question about import

Kay Schluehr kay.schluehr at
Fri Apr 25 20:26:28 CEST 2008

On 25 Apr., 20:03, Luca <luca... at> wrote:
> Hi all. I'm trying to do something with python import but isn't working for me.
> Using python 2,5 I've a program structured like this:
> * a main module called (for example) "mommy" with an and a
> file called ""
> * a __version__ var defined inside the main
> >From the file I need to import the __version__ var, but I'm
> really not able to do this! I fear this is a very stupid task to do...
> my problem is that the file is called like the module.
> Anyone can point me to the solution?
> --
> -- luca

You have to import the package containing mummy and __init__ from the
pythonpath ( which can be examined using the sys module and the
sys.path attribute ). Then access __version__ as an attribute:

mypack/               # package indicated by
import mypack      # o.k. if accessible from pythonpath

More information about the Python-list mailing list