Organizing Python Code
Russell Wallace
rwallace at esatclear.ie
Mon Oct 2 02:28:39 EDT 2000
Thomas Gagne wrote:
>
> I'm trying to do a project with Python and I'm not convinced I've set things
> up properly. In writing C code I've grown accustomed to creating separate
> files for each function.
For each function, not for each module? I wouldn't recommend this in
any language, but whatever works for you.
> This doesn't seem to really be the right thing to do
> in Python since the top of each would include a bunch of "import" or "from"
> statements. On the other extreme, I don't like having really big files
> either.
>
> What's everyone else doing? What's idiomatic?
I do basically the same as in C. I have one file per module. Each of
these has at the top:
from foo import *
where foo is the name of my project. Foo.py consists of:
from first import *
from second import *
etc, where first, second etc are the names of the modules. So each
module can access what it needs without having to carry a lot of import
statements around.
--
"To summarize the summary of the summary: people are a problem."
Russell Wallace
mailto:rwallace at esatclear.ie
http://www.esatclear.ie/~rwallace
More information about the Python-list
mailing list