473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Code organization

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

Feb 15 '06 #1
2 1335
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 'o****@xiludom.gro'.split('@')])"
Feb 15 '06 #2
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
Feb 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Amardeep Verma | last post by:
Hi, I would like to determine the Country and Organization from a given IP. I have to write a JSP, which when given the IP address gives the country and the organization to which the IP belongs....
5
by: Jo Vermeulen | last post by:
Hello, I was wondering if Java supports a feature of C# (or .NET in general), namely compiling code at runtime. This is nice for scripting purposes. Users can script the application in real...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
1
by: John F | last post by:
Currently I'm working on a C# app for a large organization (700 users nationwide). This App is still under development. I have setup code in my App to pull C# source code from a database and...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
1
by: J | last post by:
I'm early in my C# larval stage, so I'd like a little direction to help understand good code organization. Take for example a program I have written in another language that does the following: ...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
35
by: Michel Sanner | last post by:
Hello, One of the greatest feature of Python in my opinion is the way the interpreter can be used to integrate a wide variety of software packages by dynamically linking them. This approach has...
2
by: Bart Van der Donck | last post by:
Hello, I'm posting the software for one-FAQ-a-day as described on http://tinyurl.com/qcxw7 (comp.lang.javascript, July 18 2006, titled "CLJ newsgroup FAQ) and on http://tinyurl.com/ppt2s...
6
by: Jeff Gardner | last post by:
Greetings: I am attempting to get conditional output based on POSTed form data. If the posted value is either the key or value of an array, $x=key and $q=foo. elseif it is neither key nor...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.