Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

What are the best python programming patterns and practices you are using every day?

I don't mean only design patterns (there are lot of OO design patterns that can be used in python), I mean pure coding patterns and practices like:

  • the best way to organize modules
  • the best way for data parsing (performance wise)
  • usage of private functions (does this make sense, because you can access private functions outside the class)
  • what are the best modules for GUI, database etc.

Are there any new books or other kind of literature on this matter (2010/2011)?

Of course question can not be answered in one answer or one book, I thought of this question like a discussion on this matter because there is not really much written about python programming patterns and it is a very powerful language.

share|improve this question

closed as too broad by gnat, GlenH7, Giorgio, MichaelT, Kilian Foth Oct 7 '13 at 11:09

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

I like reading google style guides just to see what their take on it is. See: – c00w Jun 5 '11 at 8:47

1 Answer 1


Tests : unit tests, integration tests and functional tests are the way you must do your job.

The most surprising is unit tests is far more complex to do than others because you need to create a code structure that let you replace your dependencies on the framework by fake implementation:

For exemple you can check this code: contains fake components I next use in the setup to be sure I only use THE class I'm testing.


I'm using 'egg' to package my code and make it easy to use. So you can publish your add-on on the website

To create an egg you can use PasteScript:

To understand packaging you have to understand this:

  • distutils is just the file to say what are your dependencies and how to build & install the package
  • setuptools add the easy_install command with pypi as default egg repository (kind of apt-get). Today there is a fork of setuptools named distribute.
  • buildout add a way to get multiple version of the same eggs and it build the system path inside 'scripts' put in a bin folder:


No matter what performances are never checked first and this is bad. We are working on performances when there are performances issues. is a great tool to create performance tests.

Python provide tools to profile your code. I let you google that.


Never hide sth to other developers, useless and boring for them. 'property' make your public variable wrapped by accessor&mutator and do the job you want (never broke things)


I'm use to with postgresql. Python embed the sqlite binding since 2.5 to build tests

You should also consider that the can be used outside of Zope framework and is one of the oldest nosql database on python.


My favorite one:

Favorties packages & tools

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.