Newbie question about import

Discussion in 'Python' started by Luca, Apr 25, 2008.

  1. Luca

    Luca Guest

    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
     
    Luca, Apr 25, 2008
    #1
    1. Advertising

  2. Luca

    Kay Schluehr Guest

    On 25 Apr., 20:03, 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?
    >
    > --
    > -- 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__
     
    Kay Schluehr, Apr 25, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Opal
    Replies:
    12
    Views:
    960
    Paul Opal
    Oct 11, 2004
  2. JPractitioner
    Replies:
    13
    Views:
    20,163
    Roedy Green
    Feb 24, 2006
  3. Vitali Gontsharuk
    Replies:
    2
    Views:
    570
    Vitali Gontsharuk
    Aug 25, 2005
  4. Artur M. Piwko

    import/from import question

    Artur M. Piwko, Jun 29, 2003, in forum: Python
    Replies:
    1
    Views:
    842
    Peter Hansen
    Jul 2, 2003
  5. Dennis
    Replies:
    2
    Views:
    507
    Dennis
    Aug 18, 2003
Loading...

Share This Page