Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie question about import

Reply
Thread Tools

Newbie question about import

 
 
Luca
Guest
Posts: n/a
 
      04-25-2008
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?

--
-- luca
 
Reply With Quote
 
 
 
 
Kay Schluehr
Guest
Posts: n/a
 
      04-25-2008
On 25 Apr., 20:03, Luca <(E-Mail Removed)> 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?
>
> --
> -- 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 __init__.py
mummy.py
__init__.py


mummy.py
--------
import mypack # o.k. if accessible from pythonpath
mypack.__version__
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
to use import java.lang.* or import java.lang.Math or none at all? JPractitioner Java 13 02-24-2006 08:48 PM
XML Schema question - does "import" import elements? Vitali Gontsharuk XML 2 08-25-2005 07:33 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
GTK import doesn't import first time Dennis Python 2 08-18-2003 10:00 PM
import/from import question Artur M. Piwko Python 1 07-02-2003 07:04 PM



Advertisments