organizing your scripts, with plenty of re-use

greg greg at
Tue Oct 13 02:10:55 CEST 2009

Stef Mientki wrote:

> - I can move the complete project anywhere I like and it should still 
> work without any modifications (when I move my desk I can still do my work)

Gabriel's organisation satisfies that.

> - I can move any file in he project to any other place in the project 
> and again everything should work without any modifications

That's not a reasonable thing to expect from Python. The
position of a module in the module naming hierarchy is
implied by the location of its file in the directory
hierarchy. When you move the file, you change the name
of the module, so you have to change any import statements
that refer to it accordingly.

For example, if you decide that otters are now lizards
and move mammals/ into the lizards directory,
the module is now called lizards.otter instead of

> ( when I 
> rearrange my books, I can still find a specific book)

Only because you've updated the index in your brain that
maps book titles to their locations. If you don't do that,
you lose track of the book and have to search for it.

The Python equivalent of this is updating import statements
to reflect the new location of the module.

> In my humble opinion if these actions are not possible, there must be 
> redundant information in the collection.

Actually, it's because Python *doesn't* keep redundant
information. To be able to move files around without changing
anything else, Python would have to keep an index somewhere
mapping module names to files. But there is no such index --
the directory structure *is* the index.


More information about the Python-list mailing list