[geeks] Python resources

Joshua Boyd jdboyd at jdboyd.net
Sat Aug 2 14:36:09 CDT 2008


Does anyone have any suggestions for finding guides to how to deal with
larger python projects?

I have about 10,000 lines in one project at work, and things are
starting to get a bit out of control.  My big area of difficulty is how
to split a program into modules. 

For libraries of stand alone functions that take in data and return data
without side effects, it is certainly easy enough to stick them in a
module.  However, past that, I'm not sure the best way to structure some
things.

For instance, one of the programs in the project has a couple of
threads.  If this were C, I would put each thread and code specific to
that thread in it's own file.  Code that is used by multiple files would
get put in another seperate file(s).   Globals would be initialized in
the first file and be documented via the headers.

Now, in Python module __main__ can import module A and B, but there is
no way for modules A and B to effect globals in __main__.  Correct me if
I'm wrong.  If this was C, __main__ might contain a dictionary that
threads in A and B want to write into, for instance.

I can access a reference to the environment in __main__ with the globals
function.  Is it reasonable to somehow pass that to module A/B?  Or am I
way off track?

This is why I'm trying to look for guides to dealing with larger
projects.  I have some monsterous files that seem like they should be
split into 3 or 4, but I haven't figured out how to yet.  This is the
largest project I've ever done with Python.



More information about the geeks mailing list