Newbie question about import

Larry Bates larry.bates at websafe.com`
Fri Apr 25 14:23:02 EDT 2008


Luca 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 __init__.py and a
> file called "mommy.py"
> * a __version__ var defined inside the main __init__.py
> 
>>From the mommy.py 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?
> 

In the future please show us what you "actually" did with full tracebacks if 
there were any so we know what you actually tried.

I do something like this by doing:

from version import version__

It doesn't have to be a module (e.g. doesn't need __init__.py) to make that work.

Hope this helps.

-Larry



More information about the Python-list mailing list