How to organize Python files in a (relatively) big project

toki doki tokidokix at gmail.com
Tue Oct 18 22:03:17 EDT 2005


Hello there,

I have been programming python for a little while, now. But as I am
beginning to do more complex stuff, I am running into small organization
problems.
It is possible that what I want to obtain is not possible, but I would
appreciate the advice of more experienced python programmers.

I am writing a relatively complex program in python that has now around 40
files.
At first, I had all of my files in one single directory, but now, with the
increasing number of files, it is becoming hard to browse my directory.
So, I would want to be able to divide the files between 8 directory,
according to their purpose. The problem is that it breaks the 'import's
between my files. And besides,AFAIK, there is no easy way to import a file
that is not in a subdirectory of the current file (I suppose I could adjust
the os.path in every file, but that seems not very elegant to me).
I thought about turning the whole into a package. But I have to change every
'import module_name' into
'from package_name.sub_directory_name import module_name'
which is a little bit time consuming and not very flexible (if I change my
mind about the subdirectory a file belongs to, I will have to track again
every import to correct them)

So, basically, here is the point: is there an 'elegant' way to keep my files
in separate directory and still be able to import between them with simple
'import filename'?

And if not, what would be the standard way to organize numerous python files
belonging to the same project?

Thanks a lot for any advice,

TokiDoki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051019/137afbdf/attachment.html>


More information about the Python-list mailing list