Relative Imports, why the hell is it so hard?

CinnamonDonkey CinnamonDonkey at googlemail.com
Tue Mar 24 10:05:15 CET 2009


Thanx Max - your explanation sorted it :-), and a big thank you to
everyone else also!

>From the various posts, Python considers any directory containing the
__init__.py file to be a package. The top level package is the highest
directory (closest to root) with a __init__.py file.

Inter-package communication is not allowed unless the packages
themselves are contained by a parent package.

How does this relate to the site-packages folder? Is it a top level
package for all installed packages?

Let's say I have installed the "Trac" system which uses "Genshi", they
are both packages. They are also both installed at the same level and
I know "Trac" uses "Genshi" to work. \Python25\Lib\site-packages does
not contain a __init__.py file so it is not a package (i.e. not a
parent package to "Trac" and "Genshi") :0.


-=- bearophile -=-

Hi Bearophile,

Thanx for taking the time to post a response but I am afraid I feel
the need to point out that it is exactly this kind of response that I
find un-helpful. It is neither constructive nor educational.

It's a bit like saying "If you don't know what a function is, then
maybe you don't need it. ... have you tried having a single block of
code?"

The point of people coming to these forums is to LEARN and share
knowledge. Perhaps it's not the best solution for me right now but
without trying it I won't know when or how to apply it as a solution.

By the way, my project has about 50 files (modules) in it with a lot
of shared code that could be used across other projects... seems as
good a reason as any to try packages out ;-)

Thanx anyway :)


On 23 Mar, 18:57, bearophileH... at lycos.com wrote:
> CinnamonDonkey:
>
> >what makes something a package?
>
> If you don't know what a package is, then maybe you don't need
> packages.
>
> In your project is it possible to avoid using packages and just use
> modules in the same directory?
>
> Bye,
> bearophile




More information about the Python-list mailing list