Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Code organization

Reply
Thread Tools

Code organization

 
 
Thomas Girod
Guest
Posts: n/a
 
      02-15-2006
Hi.

I found a lot of documentation about how to code in Python, but not
much about how you organize your code in various modules / packages ...
As I am not yet used to python, this puzzle me a bit.

So, can anyone explain how one should organize and store its code ? the
uses of __init__.py files ? Maybe my question is not very clear, but I
hope someone will understand anyway ...

Thomas

 
Reply With Quote
 
 
 
 
bruno at modulix
Guest
Posts: n/a
 
      02-15-2006
Thomas Girod wrote:
> Hi.
>
> I found a lot of documentation about how to code in Python, but not
> much about how you organize your code in various modules / packages ...
> As I am not yet used to python, this puzzle me a bit.
>
> So, can anyone explain how one should organize and store its code ? the
> uses of __init__.py files ? Maybe my question is not very clear, but I
> hope someone will understand anyway ...


Well... As a starting point relative to Python specific stuff (use of
__init__.py etc), the Fine Manual is your friend:
http://www.python.org/doc/2.4.2/tut/node8.html

Now for best practices and whatnots, this isn't really specific to
Python. Try to have modules with high cohesion and low coupling, and
it'll be fine. Eventually try to provide a facade class or function for
complex packages (this is a current pattern in the standard lib).

Also, python-is-not-java, so don't feel commited to putting everything
in classes when plain functions would do, and avoid the 1:1 class/file
Java plague !-)

My 2 cents...
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in ''.split('@')])"
 
Reply With Quote
 
 
 
 
Kent Johnson
Guest
Posts: n/a
 
      02-15-2006
bruno at modulix wrote:
> Thomas Girod wrote:
>>
>>I found a lot of documentation about how to code in Python, but not
>>much about how you organize your code in various modules / packages ...
>>As I am not yet used to python, this puzzle me a bit.

>
> Now for best practices and whatnots, this isn't really specific to
> Python. Try to have modules with high cohesion and low coupling, and
> it'll be fine. Eventually try to provide a facade class or function for
> complex packages (this is a current pattern in the standard lib).


Also, be aware of dependencies between packages and make sure they are
acyclic - if a module in package A imports a module in package B, then A
depends on B and B should not be allowed to also depend on A either
directly (module in B imports module in A) or indirectly (module in B
imports module in C which imports module in A).

If you follow this rule your packages will be more testable and
reusable. The alternative tends to devolve into
everything-depends-on-everything-else which makes testing harder and
reuse nearly impossible.

Kent
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
code organization Li Chen Ruby 4 06-07-2009 05:36 PM
Template code organization dizzy C++ 2 09-12-2008 08:08 PM
Code Organization ... Really need advice shapper ASP .Net 0 09-09-2008 05:17 PM
Code organization and modules Brad Ottoson Ruby 2 02-16-2008 05:34 PM
code organization J ASP .Net 1 01-14-2008 07:57 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57