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

spinner david at jotax.com
Wed Oct 19 04:46:10 EDT 2005


I have this problem myself, and as I am a recent Python convert my
aproach may not be conventional - but as it is working for me I thought
I would share.

First off you need to split your code into logical objects.  In my case
I have an obvious client and server object,  But within each I have
individual stand alone major objects and so my directory structure
reflects this...

Prog Dir
    -- MainApp.py
    Bin
        __init__.py
        --- main.py
        --- lib.py
        Client
            __init__.py
            --- main.py
            Browser 1
                __init__.py
                --- main.py
                --- B1_file1.py
                --- B1_file2.py
            Browser 2
                __init__.py
                --- main.py
                --- B2_file1.py
                --- B2_file2.py
        Server
            __init__.py
            --- main.py
            Server Object 1
                __init__.py
                --- main.py
                --- SO1_file1.py
                --- SO1_file2.py
            Server Object 2
                __init__.py
                --- main.py
                --- SO2_file1.py
                --- SO2_file2.py


Each main.py file is used to call each downstream main.py file be it as
a thread or once only run.  The beauty of this idea is that if I want
to completely change say Server Object 2, I can do whatever I like
within the downstream directory as the only outside call is via an
external reference to the main.py file.

If you have a mind, you could have a library file of common apps held
within the bin directory that you can make available to all downstream
modules.

As I say - it only works if you can logically split your program into
independent blocks.

If there is a more Pythonesque way of doing this I be grateful if
someone could share.

HTH




More information about the Python-list mailing list