473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Newbie question about import

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
Jun 27 '08 #1
2 903
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
Jun 27 '08 #2
On 25 Apr., 20:03, Luca <luca...@gmail.comwrote:
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__
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: janetb | last post by:
Brand new to xml and I'm trying to get Scott Mitchell's rss aggregator example working locally. Basically, involves a frameset with the channels(feeds) in the left frame, a list of items in the...
1
by: sheephead86 | last post by:
Hi, I'm pretty new to java, and I have a small problem involving drawing a rectangle on a java applet.Firstly this is not a plea for someone to help me with this peice of work, I just need pointing...
0
by: Gabriel Genellina | last post by:
En Fri, 25 Apr 2008 15:03:18 -0300, Luca <lucafbb@gmail.comescribió: The short answer is: don't do that! __init__.py may import any module, but other modules in the package should not import...
7
by: idiolect | last post by:
Hi all - Sorry to plague you with another newbie question from a lurker. Hopefully, this will be simple. I have a list full of RGB pixel values read from an image. I want to test each RGB band...
1
by: Richard | last post by:
This is highly unusual. I do this only out of desperation. I am DB2 DBA on unix and recent had to take on Oracle admin as well. This question is really about Oracle export/import. Why I post here...
4
by: frankrentef | last post by:
Greetings all, I'm wanting to maintain what values in one file and call them in another. The purpose being to keep a single location where url's, login's and passwords can be maintained, then...
2
by: Ken D'Ambrosio | last post by:
First, apologies for such a newbie question; if there's a better forum (I've poked around, some) feel free to point it out to me. Anyway, a mere 25-odd years after first hearing about OOP, I've...
0
by: Albert-jan Roskam | last post by:
Hi John, Thanks! Using a higher xlrd version did the trick! Regarding your other remarks: -yep, input files with multiple sheets don't work yet. I kinda repressed that ;-) Spss outputs only...
0
by: Robert Kern | last post by:
Joe Hays wrote: You will want to ask numpy questions on the numpy mailing list (preferably with a subject line a bit more informative with respect to the actual problem). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.